How to use the react-native-track-player.setupPlayer 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 / index.js View on Github external
import TrackPlayer from 'react-native-track-player'
import { AsyncStorage } from 'react-native'
import { create } from 'mobx-persist'
import music from './music'

TrackPlayer.setupPlayer({})
  .then(() => {
    TrackPlayer.updateOptions({
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
      ]
    })
  })
    
const hydrate = create({ storage: AsyncStorage })

hydrate('music', music)
  .then(() => {
    // console.log(music.list.slice())
github Musicoin / app / components / Player.js View on Github external
import Layout from '../constants/Layout';
import TextTicker from 'react-native-text-ticker';
import Modal from 'react-native-modal';
import {tipTrack, removeFromQueue, addToQueue, playTrack, toggleRepeat, toggleShuffle, togglePlayerMode} from '../actions';
import {Icon} from 'expo';
import connectAlert from '../components/alert/connectAlert.component';
import TrackSlider from '../components/TrackSlider';
import NavigationService from '../services/NavigationService';
import {returnIndexFromArray, shareTrack} from '../tools/util';
import {getStatusBarHeight, getBottomSpace} from 'react-native-iphone-x-helper';
import {FULLSCREEN_VIEWS} from '../constants/App';
import TippingModal from '../components/TippingModal';

import TrackPlayer from 'react-native-track-player';

TrackPlayer.setupPlayer().then(() => {
  // The player is ready to be used
  updateOptions();

});

function updateOptions() {
  let options = {
    stopWithApp: true,
    capabilities: [
      TrackPlayer.CAPABILITY_PLAY,
      TrackPlayer.CAPABILITY_PAUSE,
      TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
      TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
    ],
    compactCapabilities: [
      TrackPlayer.CAPABILITY_PLAY,
github m-inan / react-native-music-app / src / reducers / Player / actions.js View on Github external
return async (dispatch, getState) => {
		TrackPlayer.updateOptions({
			capabilities: [
				TrackPlayer.CAPABILITY_PLAY,
				TrackPlayer.CAPABILITY_PAUSE,
				TrackPlayer.CAPABILITY_SEEK_TO,
				TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
				TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
			]
		})

		await TrackPlayer.setupPlayer({
			maxCacheSize: 1024 * 5 // 5 mb
		})

		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()
github d2rivendell / react-native-GCore / app / components / other / timeLine / TimeLine.js View on Github external
}).done(()=>{
            TrackPlayer.setupPlayer().then(() => {
                // The player is ready to be used
                if(play.isPlay === true ){
                    if(play.id !== id){
                        this.audioPlayer.terminate()
                        actions.play(false)
                        this.audioPlayer.initializeUrl()
                        this.audioPlayer.playAudio()
                    }
                }else {
                    this.audioPlayer.initializeUrl()
                    this.audioPlayer.playAudio()
                }

            })
            if(Platform.OS != 'android'){
                TrackPlayer.updateOptions({
github ThalKod / react-native-music-player / src / screens / NowPlaying.js View on Github external
const setupPlayer = async () => {
    await TrackPlayer.setupPlayer();
    TrackPlayer.updateOptions({
      stopWithApp: false,
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
        TrackPlayer.CAPABILITY_STOP
      ],
      compactCapabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE
      ]
    });
  };
github PierreBresson / Thinkerview / app / index.js View on Github external
componentDidMount() {
    TrackPlayer.setupPlayer();

    TrackPlayer.updateOptions({
      stopWithApp: true,
      jumpInterval: 15,
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SEEK_TO,
        TrackPlayer.CAPABILITY_JUMP_BACKWARD,
        TrackPlayer.CAPABILITY_JUMP_FORWARD,
        TrackPlayer.CAPABILITY_STOP
      ],
      compactCapabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE
      ]
github m-inan / react-native-music-app / src / Stores / index.js View on Github external
useEffect(() => {
    AppState.addEventListener('change', handleChange);
    TrackPlayer.registerEventHandler(Handler(dispatch));
    TrackPlayer.setupPlayer({})

    TrackPlayer.updateOptions({
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SEEK_TO,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS
      ]
    })

    return () => {
      AppState.removeEventListener('change', handleChange);
    }
  }, [])
github react-native-kit / react-native-track-player / example / react / screens / PlaylistScreen.js View on Github external
useEffect(() => {
    TrackPlayer.setupPlayer();
    TrackPlayer.updateOptions({
      stopWithApp: true,
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
        TrackPlayer.CAPABILITY_STOP
      ],
      compactCapabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE
      ]
    });
  }, []);
github ferrannp / react-native-spotify-streamer / src / App.js View on Github external
initPlayer = async () => {
    await TrackPlayer.setupPlayer();
  };
github moonou / siren / src / lib / sound.js View on Github external
constructor (token) {
    TrackPlayer.setupPlayer()
    if (_singleton !== token)
      throw new Error('Cannot instantiate directly.');
  }
  add (track) {