I am trying to implement react - native - track - player, but i am stuck with above error please guide me how can i resolve this error.and i have already reinstalled the app two times but in my case error is not short out.i am sharing piece of code below for reference.
- I have made a service.js file like this
import TrackPlayer from 'react-native-track-player';
module.exports = async function () {
TrackPlayer.addEventListener("remote-play", () => TrackPlayer.play())
TrackPlayer.addEventListener("remote-pause", () => TrackPlayer.pause())}
- import it in index.js like this
import {AppRegistry}from 'react-native';
import TrackPlayer from "react-native-track-player"
import {App}from './App
AppRegistry.registerComponent(appName, () => App);
TrackPlayer.registerPlaybackService(() => require("./service"))
- finally this is my setup file code please go through it.
componentDidMount() {
TrackPlayer.updateOptions({
stopWithApp: true
, capabilities: [TrackPlayer.CAPABILITY_PLAY, TrackPlayer
.CAPABILITY_PAUSE
]
, compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY
, TrackPlayer.CAPABILITY_PAUSE,
// TrackPlayer.CAPABILITY_SEEK_TO
]
, });
this.setUpTrackPlayer()
}
componentWillUnmount() {
TrackPlayer.destroy();
}
setUpTrackPlayer = async () => {
try {
await TrackPlayer.setupPlayer();
await TrackPlayer.add({
id: '1'
, url: 'n/w url'
, title: 'Example'
, artist: 'ajay'
, });
console.log('Tracks added');
}
and for play and pause i am using
TrackPlayer.play() & TrackPlayer.pause()