-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.js
23 lines (18 loc) · 877 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
import TrackPlayer from 'react-native-track-player';
// module.exports =async function (){
// TrackPlayer.addEventListener('remote-play',()=>TrackPlayer.play());
// TrackPlayer.addEventListener('remote-pause',()=>TrackPlayer.pause());
// }
import { useEffect } from 'react'; // Import useEffect hook
const useTrackPlayerService = () => {
useEffect(() => {
TrackPlayer.addEventListener('remote-play', () => TrackPlayer.play());
TrackPlayer.addEventListener('remote-pause', () => TrackPlayer.pause());
return () => {
TrackPlayer.removeEventListener('remote-play', () => TrackPlayer.play());
TrackPlayer.removeEventListener('remote-pause', () => TrackPlayer.pause());
};
}, []); // Empty dependency array to run effect only once
// Return any cleanup function or additional logic if needed
};
export default useTrackPlayerService;