How to use the react-native-track-player.getDuration 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 moonou / siren / src / store / models / music.js View on Github external
TrackPlayer.registerEventHandler(async (data) => {
  switch (data.type) {
    case 'remote-play':
      await music.play()
      break
    case 'remote-pause':
      await music.pause()
      break
    case 'playback-state':
      // WIP[] accurate case state 
      let durantion = await TrackPlayer.getDuration()
      let position = await TrackPlayer.getPosition()
      const state = await TrackPlayer.getState()
      if(state === TrackPlayerType.STATE_PAUSED && durantion === position) {
        await music.playNext()
      }
      break
  }

  await music.updateState()
})
github ferrannp / react-native-spotify-streamer / src / PlayerControls.js View on Github external
_onPlayPause = async () => {
    const state = this.props.playerState;

    if (state === STATE_PLAYING) {
      await TrackPlayer.pause();
    } else if (state === STATE_PAUSED) {
      const position = Math.round(await TrackPlayer.getPosition());
      const duration = Math.round(await TrackPlayer.getDuration());
      if (position === duration) {
        // It's finished
        this._playNewTrack();
      } else {
        await TrackPlayer.play();
      }
    } else {
      this._playNewTrack();
    }
  };
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 d2rivendell / react-native-GCore / app / components / other / timeLine / AudioPlayer.js View on Github external
async timeFunc() {
        const {getProgress} = this.props
        if(getProgress ) {
            let state =  await  TrackPlayer.getState()
            let position = await TrackPlayer.getPosition()
            let duration = await TrackPlayer.getDuration();
            getProgress(state,position,duration)
            if(this.props.pageInfo){
                this.setState({
                    value:(position/this.props.pageInfo.duration) * 100
                })
            }
        }
    }
github m-inan / react-native-music-app / src / scenes / Player / Slider.js View on Github external
const changePlaybackTrack = async () => {
		const currentDuration = await TrackPlayer.getDuration()
		setDuration(currentDuration)
	}
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
			}
		})
	}
}