我正在尝试实现 react - native - track - player,但我遇到了上述错误 请指导我如何解决此错误。我已经重新安装了该应用程序 两次,但在我的 案例错误不短。我在下面分享一段代码 供参考。
import TrackPlayer from 'react-native-track-player';
module.exports = async function () {
TrackPlayer.addEventListener("remote-play", () => TrackPlayer.play())
TrackPlayer.addEventListener("remote-pause", () => TrackPlayer.pause())}
<块引用>
import {AppRegistry}from 'react-native';
import TrackPlayer from "react-native-track-player"
import {App}from './App
AppRegistry.registerComponent(appName, () => App);
TrackPlayer.registerPlaybackService(() => require("./service"))
<块引用>
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()