-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice.js
42 lines (34 loc) · 1.09 KB
/
service.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, { Event, State } from 'react-native-track-player';
import { Next, Previous } from './src/utils/play';
let wasPausedByDuck = false;
TrackPlayer.addEventListener([Event.PlaybackQueueEnded], () => {
console.log('get song from background')
Next()
})
module.exports = async function setup() {
TrackPlayer.addEventListener(Event.RemotePause, () => {
TrackPlayer.pause();
});
TrackPlayer.addEventListener(Event.RemotePlay, () => {
TrackPlayer.play();
});
TrackPlayer.addEventListener(Event.RemoteNext, () => {
Next()
});
TrackPlayer.addEventListener(Event.RemotePrevious, async () => {
Previous()
});
TrackPlayer.addEventListener(Event.RemoteDuck, async e => {
if (e.paused === true) {
const playerState = await TrackPlayer.getState();
wasPausedByDuck = playerState !== State.Paused;
TrackPlayer.pause();
} else {
if (wasPausedByDuck === true) {
TrackPlayer.play();
wasPausedByDuck = false;
}
}
});
TrackPlayer.addEventListener(Event.RemoteSeek, ({ position }) => TrackPlayer.seekTo(position));
};