How to use react-native-track-player - 10 common examples

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 PierreBresson / Thinkerview / app / actions / playerActions.js View on Github external
return async (dispatch, getState) => {
        try {
            dispatch(playbackState(await TrackPlayer.getState()));
            dispatch(playbackTrack(await TrackPlayer.getCurrentTrack()));
        } catch(e) {
            // The player is probably not yet initialized
            // which means we don't have to update anything
            console.log(e);
        }
    };
}
github moonou / siren / src / store / models / index.js View on Github external
import TrackPlayer from 'react-native-track-player'
import { AsyncStorage } from 'react-native'
import { create } from 'mobx-persist'
import music from './music'

TrackPlayer.setupPlayer({})
  .then(() => {
    TrackPlayer.updateOptions({
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
      ]
    })
  })
    
const hydrate = create({ storage: AsyncStorage })

hydrate('music', music)
  .then(() => {
    // console.log(music.list.slice())
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 Musicoin / app / components / Player.js View on Github external
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());
  }
github m-inan / react-native-music-app / src / provider / service.js View on Github external
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 => {
github PierreBresson / Thinkerview / app / event-handler.js View on Github external
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) {
github Musicoin / app / components / Player.js View on Github external
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());
  }
github Musicoin / app / components / Player.js View on Github external
async resumeTrack() {
    // play again if track has finished playing
    let position = await TrackPlayer.getPosition();
    if (position > 0) {
      await TrackPlayer.play();
    } else {
      this.props.playTrack(this.props.currentTrack, false);
    }
  }
github m-inan / react-native-music-app / src / Scenes / Player / Slider.js View on Github external
onPanResponderRelease: () => {
			// end
			TrackPlayer.seekTo((duration / 100) * percent)

			setMoveSlider(false)
		},
		onPanResponderGrant: ({ nativeEvent: { locationX, locationY } }) =>
github m-inan / react-native-music-app / src / reducers / Player / handler.js View on Github external
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

			break
		case 'playback-error':