-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.js
26 lines (23 loc) · 872 Bytes
/
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
import TrackPlayer, {Event, State} from 'react-native-track-player';
module.exports = async function () {
TrackPlayer.addEventListener(Event.RemotePlay, () => TrackPlayer.play());
TrackPlayer.addEventListener(Event.RemotePause, () => TrackPlayer.pause());
TrackPlayer.addEventListener(Event.RemoteStop, () => TrackPlayer.destroy());
TrackPlayer.addEventListener(Event.RemoteNext, () =>
TrackPlayer.skipToNext(),
);
TrackPlayer.addEventListener(Event.RemotePrevious, () =>
TrackPlayer.skipToPrevious(),
);
TrackPlayer.addEventListener(Event.RemoteSeek, async pos => {
await TrackPlayer.seekTo(pos.position);
});
TrackPlayer.addEventListener(Event.RemoteDuck, async () => {
const state = await TrackPlayer.getState();
if (state === State.Playing) {
return TrackPlayer.pause();
}
TrackPlayer.play();
});
// ...
};