How to use the react-native-track-player.getCurrentTrack 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 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 AbelTesfaye / dingo / src / UI / CustomModules / JS / MiniPlayer.js View on Github external
async _updateProgress() {
		try {
			const data = {
				position: await TrackPlayer.getPosition(),
				bufferedPosition: await TrackPlayer.getBufferedPosition(),
				duration: await TrackPlayer.getDuration(),
				track: await TrackPlayer.getTrack(await TrackPlayer.getCurrentTrack()),
			};

			if (this._progressUpdates) {
				this.setState(data);
			}
		} catch (e) {
			// The player is probably not initialized yet, we'll just ignore it
		}
	}
github ferrannp / react-native-spotify-streamer / src / PlayerControls.js View on Github external
_checkChangeSelectedTrack = async () => {
    let isCurrentTrack;
    isCurrentTrack = await !!TrackPlayer.getCurrentTrack().catch(() => {
      // If nothing is playing, it rejects the promise
      isCurrentTrack = false;
    });
    if (isCurrentTrack) {
      this._playNewTrack();
    }
  };
github AbelTesfaye / dingo / src / BL / Services / event-handler-service.js View on Github external
.then(tracks => {
				TrackPlayer.getCurrentTrack().then(currentTrackId => {
					const currentItemIndex = utils.getIndexOfTrackUsingId(tracks, currentTrackId);

					const tracksToLeft = this._getTracksToLeft(tracks, currentItemIndex, amountOfTracksToLeft);
					trackCurrent = tracks[currentItemIndex];
					const tracksToRight = this._getTracksToRight(tracks, currentItemIndex, amountOfTracksToRight);

					[shouldFetchCurrent ? trackCurrent : {}, ...tracksToRight, ...tracksToLeft].map((item, index) => {
						if (item.videoId && ytdl.validateID(item.videoId)) {
							this._ytdlGetInfo(
								item.videoId,
								info => {
									console.log(JSON.stringify(info));
									const highestQualityAudio = this._filterHighestQualityAudio(info.formats);

									this._updateTrackPlayerQueueItem(
										tracks,
github AbelTesfaye / dingo / App.js View on Github external
_getCurrentTrackId = callback => {
		TrackPlayer.getCurrentTrack()
			.then(trackid => {
				callback(trackid);
			})
			.catch(e => console.error(e));
	};
github m-inan / react-native-music-app / src / reducers / Player / actions.js View on Github external
return async dispatch => {
		const trackId = await TrackPlayer.getCurrentTrack()
		const duration = await TrackPlayer.getDuration()

		const track = await TrackPlayer.getTrack(trackId)

		dispatch({
			type: types.TRACK,
			payload: {
				track,
				duration
			}
		})
	}
}
github ThalKod / react-native-music-player / src / screens / NowPlaying.js View on Github external
const togglePlayback = async () => {
    const currentTrack = await TrackPlayer.getCurrentTrack();
    if(currentTrack){
      if (playbackState === TrackPlayer.STATE_PAUSED) {
        await TrackPlayer.play();
      } else {
        await TrackPlayer.pause();
      }
    }
  };
github react-native-kit / react-native-track-player / example / react / screens / PlaylistScreen.js View on Github external
async function togglePlayback() {
    const currentTrack = await TrackPlayer.getCurrentTrack();
    if (currentTrack == null) {
      await TrackPlayer.reset();
      await TrackPlayer.add(playlistData);
      await TrackPlayer.add({
        id: "local-track",
        url: localTrack,
        title: "Pure (Demo)",
        artist: "David Chavez",
        artwork: "https://picsum.photos/200"
      });
      await TrackPlayer.play();
    } else {
      if (playbackState === TrackPlayer.STATE_PAUSED) {
        await TrackPlayer.play();
      } else {
        await TrackPlayer.pause();