How to use the react-native-track-player.addEventListener 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 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 m-inan / react-native-music-app / src / provider / service.js View on Github external
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.')
	})
}
github m-inan / react-native-music-app / src / provider / service.js View on Github external
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 {