-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerService.js
62 lines (51 loc) · 1.46 KB
/
playerService.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import TrackPlayer from 'react-native-track-player';
import {
Platform,
} from 'react-native';
import { checkForAdvert } from './src/helper'
module.exports = async function () {
TrackPlayer.addEventListener('remote-play', async () => {
TrackPlayer.play()
})
TrackPlayer.addEventListener('remote-pause', () => {
TrackPlayer.pause()
});
TrackPlayer.addEventListener('remote-next', async () => {
checkForAdvert('nextTrack')
});
TrackPlayer.addEventListener('remote-previous', async () => {
checkForAdvert('previousTrack')
});
TrackPlayer.addEventListener('remote-stop', () => {
TrackPlayer.stop()
});
TrackPlayer.addEventListener('remote-duck', async (data) => {
if (Platform.OS === 'ios') {
if (data.paused) {
TrackPlayer.pause()
}
else {
TrackPlayer.play()
}
} else if (Platform.OS === 'android') {
if (data.paused) {
const currentState = await TrackPlayer.getState();
wasPlaying = currentState === TrackPlayer.STATE_PLAYING;
TrackPlayer.pause();
} else if (wasPlaying) {
TrackPlayer.play();
wasPlaying = false;
} else if (data.permanent) {
TrackPlayer.stop()
}
}
});
TrackPlayer.addEventListener('playback-queue-ended', (data) => {
if (data.track) {
checkForAdvert('nextTrack')
}
});
TrackPlayer.addEventListener('remote-seek', async (data) => {
TrackPlayer.seekTo(data.position)
});
};