How to use the react-native-track-player.getPosition 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 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 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 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 / Controllers.js View on Github external
const onPressPrev = async () => {
		const time = await TrackPlayer.getPosition()

		if (time <= 3) {
			TrackPlayer.skipToPrevious()
		} else {
			TrackPlayer.seekTo(0)
		}
	}
github PierreBresson / Thinkerview / app / screens / podcast / index.js View on Github external
_addOrRemoveSeconds = async seconds => {
    let position = await TrackPlayer.getPosition();
    TrackPlayer.seekTo(position + seconds);
  };
github m-inan / react-native-music-app / src / reducers / Player / actions.js View on Github external
setInterval(async () => {
			const [position, duration] = await Promise.all([
				TrackPlayer.getPosition(),
				TrackPlayer.getDuration()
			])

			const { replay, shuffle, track } = getState().Player

			if (position && duration && position >= duration) {
				if (replay) {
					await TrackPlayer.seekTo(0)
				} else if (shuffle) {
					let queue = await TrackPlayer.getQueue()
					queue = queue.filter(item => item.id !== track.id)

					const count = queue.length - 1
					const index = Math.floor(Math.random() * count)

					const trackId = queue[index].id
github m-inan / react-native-music-app / src / scenes / Player / Slider.js View on Github external
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
github m-inan / react-native-music-app / src / Stores / index.js View on Github external
interval = setInterval(async () => {
        const position = await TrackPlayer.getPosition()
        dispatch(updateTime(position))
      }, 500)
    }