How to use the react-native-track-player.STATE_PLAYING function in react-native-track-player

To help you get started, we’ve selected a few react-native-track-player examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AbelTesfaye / dingo / src / BL / Services / event-handler-service.js View on Github external
//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
						);
					}
github react-native-kit / react-native-track-player / example / react / screens / PlaylistScreen.js View on Github external
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";
  }
}
github m-inan / react-native-music-app / src / scenes / Player / Record.js View on Github external
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
github Musicoin / app / components / Player.js View on Github external
this.playPreviousTrack()}>
                      
                    
                    {this.state.playerState === TrackPlayer.STATE_PLAYING ?
                         this.pauseTrack()}>
                          
                         :
                         this.resumeTrack()}>
                          
                        }
github m-inan / react-native-music-app / src / scenes / Player / Slider.js View on Github external
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])
github react-native-kit / react-native-track-player / example / react / components / Player.js View on Github external
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 (
github m-inan / react-native-music-app / src / components / Icons / Music.js View on Github external
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:
github PierreBresson / Thinkerview / app / context / index.js View on Github external
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;
      }
    }