Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// The player is ready to be used
if(play.isPlay === true ){
if(play.id !== id){
this.audioPlayer.terminate()
actions.play(false)
this.audioPlayer.initializeUrl()
this.audioPlayer.playAudio()
}
}else {
this.audioPlayer.initializeUrl()
this.audioPlayer.playAudio()
}
})
if(Platform.OS != 'android'){
TrackPlayer.updateOptions({
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SEEK_TO,
TrackPlayer.CAPABILITY_STOP
],
});
TrackPlayer.registerEventHandler(() => {
return async (data) => {
if (data.type == 'playback-state') {
} else if (data.type == 'remote-play') {
this.audioPlayer.playAudio()
} else if (data.type == 'remote-stop') {
return async (dispatch, getState) => {
TrackPlayer.updateOptions({
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SEEK_TO,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
]
})
await TrackPlayer.setupPlayer({
maxCacheSize: 1024 * 5 // 5 mb
})
setInterval(async () => {
const [position, duration] = await Promise.all([
TrackPlayer.getPosition(),
function updateOptions() {
let options = {
stopWithApp: true,
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
],
compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
],
};
TrackPlayer.updateOptions(options).then(() => console.log('capabilities set'));
}
.then(() => {
TrackPlayer.updateOptions({
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
]
})
})
useEffect(() => {
AppState.addEventListener('change', handleChange);
TrackPlayer.registerEventHandler(Handler(dispatch));
TrackPlayer.setupPlayer({})
TrackPlayer.updateOptions({
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SEEK_TO,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
]
})
return () => {
AppState.removeEventListener('change', handleChange);
}
}, [])
const setupPlayer = async () => {
await TrackPlayer.setupPlayer();
TrackPlayer.updateOptions({
stopWithApp: false,
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
TrackPlayer.CAPABILITY_STOP
],
compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE
]
});
};
useEffect(() => {
TrackPlayer.setupPlayer();
TrackPlayer.updateOptions({
stopWithApp: true,
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
TrackPlayer.CAPABILITY_STOP
],
compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE
]
});
}, []);
componentDidMount() {
TrackPlayer.setupPlayer();
TrackPlayer.updateOptions({
stopWithApp: true,
jumpInterval: 15,
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SEEK_TO,
TrackPlayer.CAPABILITY_JUMP_BACKWARD,
TrackPlayer.CAPABILITY_JUMP_FORWARD,
TrackPlayer.CAPABILITY_STOP
],
compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE
]
});
}