Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.writeRecentTrack(
new Date().getTime(),
track.title,
track.artist,
track.artwork,
track.videoId
);
}
previousPlayingTrack.title = track.title;
previousPlayingTrack.artist = track.artist;
previousPlayingTrack.artwork = track.artwork;
});
});
}
if (data.state == TrackPlayer.STATE_PAUSED) {
console.log('STATE_PAUSED');
}
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') {
import {
PLAYBACK_INIT,
PLAYBACK_STATE,
PLAYBACK_TRACK,
UPDATE_TRACK_INFO
} from "../actions/types";
import TrackPlayer from 'react-native-track-player';
import config from '../config'
const initialPlayerReducer = {
init: null,
player_state: TrackPlayer.STATE_PAUSED,
track: {
title: config.strings.podcastScreen.title,
url: null,
artwork: null
}
}
export default playerReducer = (state = initialPlayerReducer, action) => {
switch(action.type) {
case PLAYBACK_INIT:
return {
...state,
init: true
};
case PLAYBACK_STATE:
return {
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";
}
}
_togglePlayPause = () => {
if (this.props.player_state == TrackPlayer.STATE_PAUSED) {
TrackPlayer.play();
} else {
TrackPlayer.pause();
}
};
renderControls = () => {
return (
);
};
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:
slide.stopAnimation()
break
}
}, [state])
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;
}
}
const togglePlayback = async () => {
const currentTrack = await TrackPlayer.getCurrentTrack();
if(currentTrack){
if (playbackState === TrackPlayer.STATE_PAUSED) {
await TrackPlayer.play();
} else {
await TrackPlayer.pause();
}
}
};
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
case STATE_READY:
spinValue.flattenOffset()
break
}
}, [state])