-
Notifications
You must be signed in to change notification settings - Fork 0
/
musicPlayerServices.js
39 lines (32 loc) · 952 Bytes
/
musicPlayerServices.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import TrackPlayer, { Event, RepeatMode } from "react-native-track-player";
import { playListData } from "./src/constants";
export async function setupPlayer(){
let isSetup =false;
try{
await TrackPlayer.getCurrentTrack()
isSetup =true
}catch(err){
await TrackPlayer.setupPlayer()
isSetup=true;
}finally{
return isSetup
}
}
export async function addTrack (){
await TrackPlayer.add(playListData)
await TrackPlayer.setRepeatMode(RepeatMode.Queue);
}
export async function playbackService (){
TrackPlayer.addEventListener(Event.RemotePause, ()=>{
TrackPlayer.pause()
})
TrackPlayer.addEventListener(Event.RemotePlay, ()=>{
TrackPlayer.play()
})
TrackPlayer.addEventListener(Event.RemoteNext, ()=>{
TrackPlayer.skipToNext()
})
TrackPlayer.addEventListener(Event.RemotePrevious, ()=>{
TrackPlayer.skipToPrevious()
})
}