Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//use this to save listened tracks into files
console.log('data.type: ' + data.type);
if (data.type == 'playback-error' && data.code == 'playback-source') {
globals.isFetchingURL = true;
_fetchURLs(true, 0, 0, () => TrackPlayer.play(), () => (globals.isFetchingURL = false));
}
if (data.type == 'playback-state') {
// Update the UI with the new state
console.log(JSON.stringify(data));
if (data.state == TrackPlayer.STATE_NONE) {
console.log('STATE_NONE');
}
if (data.state == TrackPlayer.STATE_PLAYING) {
console.log('STATE_PLAYING');
TrackPlayer.getCurrentTrack().then(currentTrackId => {
TrackPlayer.getTrack(currentTrackId).then(track => {
if (
previousPlayingTrack.title !== track.title ||
previousPlayingTrack.artist !== track.artist ||
previousPlayingTrack.artwork !== track.artwork
) {
this.writeRecentTrack(
new Date().getTime(),
track.title,
track.artist,
track.artwork,
track.videoId
);
}
function getStateName(state) {
switch (state) {
case TrackPlayer.STATE_NONE:
return "None";
case TrackPlayer.STATE_PLAYING:
return "Playing";
case TrackPlayer.STATE_PAUSED:
return "Paused";
case TrackPlayer.STATE_STOPPED:
return "Stopped";
case TrackPlayer.STATE_BUFFERING:
return "Buffering";
}
}
useEffect(() => {
switch (state) {
case TrackPlayer.STATE_PLAYING:
Animated.loop(
Animated.sequence([
Animated.timing(spinValue, {
toValue: 1,
duration: 10000,
easing: Easing.linear
})
])
).start()
break
case TrackPlayer.STATE_PAUSED:
spinValue.stopAnimation()
spinValue.extractOffset()
break
this.playPreviousTrack()}>
{this.state.playerState === TrackPlayer.STATE_PLAYING ?
this.pauseTrack()}>
:
this.resumeTrack()}>
}
useEffect(() => {
clearInterval(interval)
switch (state) {
case STATE_READY:
setPercent(0)
setTime(0)
break
case TrackPlayer.STATE_PLAYING:
interval = setInterval(async () => {
if (!moveSlider) {
const current = Math.floor(await TrackPlayer.getPosition())
if (duration && current) {
setTime(current)
setPercent((current * 100) / Math.floor(duration))
}
}
}, 100)
break
}
}, [state, moveSlider])
const [trackArtist, setTrackArtist] = useState("");
useTrackPlayerEvents(["playback-track-changed"], async event => {
if (event.type === TrackPlayer.TrackPlayerEvents.PLAYBACK_TRACK_CHANGED) {
const track = await TrackPlayer.getTrack(event.nextTrack);
setTrackTitle(track.title);
setTrackArtist(track.artist);
setTrackArtwork(track.artwork);
}
});
const { style, onNext, onPrevious, onTogglePlayback } = props;
var middleButtonText = "Play";
if (
playbackState === TrackPlayer.STATE_PLAYING ||
playbackState === TrackPlayer.STATE_BUFFERING
) {
middleButtonText = "Pause";
}
return (
useEffect(() => {
switch (state) {
case TrackPlayer.STATE_PLAYING:
Animated.loop(
Animated.sequence([
Animated.timing(slide, {
toValue: 5,
duration: 1000
}),
Animated.timing(slide, {
toValue: 0,
duration: 1000
})
])
).start()
break
case TrackPlayer.STATE_STOPPED:
case TrackPlayer.STATE_PAUSED:
async playPause() {
let state = await player.getState();
switch (state) {
case TrackPlayer.STATE_PAUSED:
player.play()
break;
case TrackPlayer.STATE_PLAYING:
player.pause()
break;
default:
break;
}
}