Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
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,
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()
}).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({
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
]
});
};
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
]
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);
}
}, [])
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
]
});
}, []);
initPlayer = async () => {
await TrackPlayer.setupPlayer();
};
constructor (token) {
TrackPlayer.setupPlayer()
if (_singleton !== token)
throw new Error('Cannot instantiate directly.');
}
add (track) {