-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusicPlayerService.js
42 lines (32 loc) · 964 Bytes
/
musicPlayerService.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
40
41
42
import TrackPlayer, { RepeatMode } from "react-native-track-player";
import { playListData } from "./src/constants";
export async function setupPlayer(){
let isSetup = false;
try {
await TrackPlayer.getActiveTrackIndex()
isSetup = true;
} catch (error) {
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()
})
}