How to use the react-native-track-player.getTrack 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
async play (trackId, addHistory = true) {
    if (this.list.length === 0) return
    
    if (trackId) {
      let track = this.list.find((i) => i.id === trackId)
  
      if (!track) {
        return new Error('歌曲未添加到列表')
      }
      
      let playerQueenTrack = true
      try {
        await TrackPlayer.getTrack(track.id)
      } catch (e) {
        console.log('查询错误', e)
        playerQueenTrack = false
      }
      if (!playerQueenTrack) {
        
        if (!track.artwork) {
          track.artwork = 'http://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg'
        }
        
        console.log('add Track', track)
        await TrackPlayer.add(track)
      }

      if (addHistory) {
        this.history.push(this.trackId)
github AbelTesfaye / dingo / App.js View on Github external
this._getCurrentTrackId(trackid => {
			TrackPlayer.getTrack(trackid)
				.then(track => {
					this.setState({
						screenStates_screenPlayerStates_pageQueueStates_currentPlayingTrack: track,
					});
					this._updateIndexOfCurrentPlayingItemState();
				})
				.catch(e => console.log(e));
		});
	};
github AbelTesfaye / dingo / App.js View on Github external
this._onTrackChanged = TrackPlayer.addEventListener('playback-track-changed', async data => {
					if (globals.shouldUIRespondToEvents) {
						if (data.nextTrack) {
							const track = await TrackPlayer.getTrack(data.nextTrack);

							this.setState({
								screenStates_screenPlayerStates_pageQueueStates_currentPlayingTrack: track,
							});
						}
						this.getTrackPlayerQueueToState();
						this.updateCurrentPlayingTrackState();
					}
				});
			})
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 react-native-kit / react-native-track-player / example / react / components / Player.js View on Github external
useTrackPlayerEvents(["playback-track-changed"], async event => {
    if (event.type === TrackPlayer.TrackPlayerEvents.PLAYBACK_TRACK_CHANGED) {
      const track = await TrackPlayer.getTrack(event.nextTrack);
      setTrackTitle(track.title);
      setTrackArtist(track.artist);
      setTrackArtwork(track.artwork);
    }
  });
github ThalKod / react-native-music-player / src / screens / NowPlaying.js View on Github external
const onTrackChange = TrackPlayer.addEventListener('playback-track-changed', async (data) => {
      const track = await TrackPlayer.getTrack(data.nextTrack);
      setMusic(prevState => ({
        ...prevState,
        selected: track
      }));
    });