0

我正在尝试实现 react - native - track - player,但我遇到了上述错误,请指导我如何解决这个错误。我已经重新安装了两次应用程序,但在我的情况下,错误并不短。我我在下面分享一段代码以供参考。

  1. 我已经制作了一个这样的 service.js 文件
    import TrackPlayer from 'react-native-track-player';
    module.exports = async function () {
    TrackPlayer.addEventListener("remote-play", () => TrackPlayer.play())
    TrackPlayer.addEventListener("remote-pause", () => TrackPlayer.pause())}
  1. 像这样在 index.js 中导入它
    import {AppRegistry}from 'react-native';
    import TrackPlayer from "react-native-track-player"
    import {App}from './App  
    AppRegistry.registerComponent(appName, () => App);
    TrackPlayer.registerPlaybackService(() => require("./service"))
  1. 最后这是我的设置文件代码,请通过它。
     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()
4

0 回答 0