Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switch (data.type) {
// Forward remote events to the player
case 'remote-play':
TrackPlayer.play();
break;
case 'remote-pause':
TrackPlayer.pause();
break;
case 'remote-stop':
TrackPlayer.stop();
break;
case 'remote-next':
TrackPlayer.skipToNext();
break;
case 'remote-previous':
TrackPlayer.skipToPrevious();
break;
case 'remote-seek':
TrackPlayer.seekTo(data.position);
break;
// You can make ducking smoother by adding a fade in/out
case 'remote-duck':
TrackPlayer.setVolume(data.ducking ? 0.5 : 1);
break;
// Playback updates
case 'playback-state': {
dispatch(playbackState(data.state));
break;
}
case 'playback-track-changed':
break;
case 'playback-error':
async function Handler(dispatch, data) {
switch (data.type) {
case 'remote-play':
TrackPlayer.play()
break
case 'remote-pause':
TrackPlayer.pause()
break
case 'remote-stop':
TrackPlayer.stop()
break
case 'remote-next':
TrackPlayer.skipToNext()
break
case 'remote-previous':
TrackPlayer.skipToPrevious()
break
case 'remote-seek':
TrackPlayer.seekTo(data.position)
break
case 'remote-duck':
TrackPlayer.setVolume(data.ducking ? 0.5 : 1)
break
case 'playback-state':
dispatch(playbackState(data.state))
break
case 'playback-track-changed':
dispatch(playbackTrack(data.nextTrack))
break
case 'playback-queue-ended':
// finish
}
if (data.state == TrackPlayer.STATE_STOPPED) {
console.log('STATE_STOPPED');
}
if (data.state == TrackPlayer.STATE_BUFFERING) {
console.log('STATE_BUFFERING');
_fetchURLs(false, 1, 1, () => {}, () => {});
}
} else if (data.type == 'remote-play') {
TrackPlayer.play();
} else if (data.type == 'remote-pause') {
TrackPlayer.pause();
} else if (data.type == 'remote-next') {
TrackPlayer.skipToNext();
} else if (data.type == 'remote-previous') {
TrackPlayer.skipToPrevious();
} else if (data.type == 'remote-seek') {
TrackPlayer.seekTo(data.position);
} else if (data.type == 'remote-duck') {
if (data.paused) TrackPlayer.pause();
if (data.permanent) TrackPlayer.stop();
if (data.ducking) {
const prevVolume = await TrackPlayer.getVolume();
TrackPlayer.setVolume(0.1);
BackgroundTimer.setTimeout(() => {
TrackPlayer.setVolume(prevVolume);
}, 3 * 1000);
}
}
};
const onPressPrev = async () => {
const time = await TrackPlayer.getPosition()
if (time <= 3) {
TrackPlayer.skipToPrevious()
} else {
TrackPlayer.seekTo(0)
}
}
TrackPlayer.addEventListener('remote-previous', () => {
TrackPlayer.skipToPrevious()
});
TrackPlayer.addEventListener('remote-previous', async () => {
const time = await TrackPlayer.getPosition()
if (time <= 3) {
TrackPlayer.skipToPrevious()
} else {
TrackPlayer.seekTo(0)
}
})
const skipToPrevious = async () => {
try {
await TrackPlayer.skipToPrevious();
} catch (_) {}
};
async function skipToPrevious() {
try {
await TrackPlayer.skipToPrevious();
} catch (_) {}
}