Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
this.checkPreviousAndNext();
this.onPlayerUpdate = TrackPlayer.addEventListener('playback-state', (data) => this.onPlaybackStatusUpdate(data));
this.onPlayerError = TrackPlayer.addEventListener('playback-error', (data) => this.onPlaybackError(data));
this.onPlayerQueueEnded = TrackPlayer.addEventListener('playback-queue-ended', (data) => this.onQueueEnded(data));
TrackPlayer.addEventListener('remote-play', () => this.resumeTrack());
TrackPlayer.addEventListener('remote-pause', () => this.pauseTrack());
TrackPlayer.addEventListener('remote-previous', () => this.playPreviousTrack());
TrackPlayer.addEventListener('remote-next', () => this.playNextTrack());
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
// TrackPlayer.addEventListener('remote-stop', () => TrackPlayer.destroy());
}
const time = await TrackPlayer.getPosition()
if (time <= 3) {
TrackPlayer.skipToPrevious()
} else {
TrackPlayer.seekTo(0)
}
})
TrackPlayer.addEventListener('remote-seek', ({ position }) =>
TrackPlayer.seekTo(position)
)
if (Platform.OS !== 'ios') {
// this event type is not supported on iOS
TrackPlayer.addEventListener('remote-duck', ({ ducking }) => {
TrackPlayer.setVolume(ducking ? 0.5 : 1)
})
}
TrackPlayer.addEventListener('playback-state', () =>
dispatch(playbackState())
)
TrackPlayer.addEventListener('playback-track-changed', () => {
dispatch(playbackTrack())
})
TrackPlayer.addEventListener('playback-queue-ended', ({ position }) => {
dispatch(playbackQueueEnded(position))
})
TrackPlayer.addEventListener('playback-error', error => {
TrackPlayer.play();
});
TrackPlayer.addEventListener("remote-pause", () => {
TrackPlayer.pause();
});
TrackPlayer.addEventListener("remote-stop", () => {
TrackPlayer.stop();
});
TrackPlayer.addEventListener("remote-seek", () => {
TrackPlayer.seekTo(data.position);
});
TrackPlayer.addEventListener("remote-jump-backward", () => {
TrackPlayer.seekTo(data.position - 15);
});
TrackPlayer.addEventListener("remote-jump-forward", () => {
TrackPlayer.seekTo(data.position + 15);
});
if (Platform.OS !== "ios") {
// this event type is not supported on iOS
TrackPlayer.addEventListener("remote-duck", () => {
TrackPlayer.setVolume(data.ducking ? 0.5 : 1);
});
}
TrackPlayer.addEventListener("playback-state", async data => {
if (data.state) {
componentDidMount() {
this.checkPreviousAndNext();
this.onPlayerUpdate = TrackPlayer.addEventListener('playback-state', (data) => this.onPlaybackStatusUpdate(data));
this.onPlayerError = TrackPlayer.addEventListener('playback-error', (data) => this.onPlaybackError(data));
this.onPlayerQueueEnded = TrackPlayer.addEventListener('playback-queue-ended', (data) => this.onQueueEnded(data));
TrackPlayer.addEventListener('remote-play', () => this.resumeTrack());
TrackPlayer.addEventListener('remote-pause', () => this.pauseTrack());
TrackPlayer.addEventListener('remote-previous', () => this.playPreviousTrack());
TrackPlayer.addEventListener('remote-next', () => this.playNextTrack());
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
// TrackPlayer.addEventListener('remote-stop', () => TrackPlayer.destroy());
}
TrackPlayer.setVolume(ducking ? 0.5 : 1)
})
}
TrackPlayer.addEventListener('playback-state', () =>
dispatch(playbackState())
)
TrackPlayer.addEventListener('playback-track-changed', () => {
dispatch(playbackTrack())
})
TrackPlayer.addEventListener('playback-queue-ended', ({ position }) => {
dispatch(playbackQueueEnded(position))
})
TrackPlayer.addEventListener('playback-error', error => {
console.log(error)
Alert.alert('Something went wrong. Please try again later.')
})
}
async function Handler(dispatch) {
TrackPlayer.addEventListener('remote-play', () =>
dispatch(setUserPlaying(true))
)
TrackPlayer.addEventListener('remote-pause', () =>
dispatch(setUserPlaying(false))
)
TrackPlayer.addEventListener('remote-stop', () => {
dispatch(setUserPlaying(false))
TrackPlayer.stop()
})
TrackPlayer.addEventListener('remote-next', () => TrackPlayer.skipToNext())
TrackPlayer.addEventListener('remote-previous', async () => {
const time = await TrackPlayer.getPosition()
if (time <= 3) {
TrackPlayer.skipToPrevious()
} else {