首页 > 解决方案 > CarPlay CPNowPlayingTemplate 播放器按钮不起作用

问题描述

但是我实现了正确的 MPRemoteCommandCenter 功能,播放按钮在 carplay 应用程序中根本没有响应。

(使用 MPPlayableContentManager 在 iOS 14 之前的 CarPlay 中可以正常工作)

没有调用 MPRemoteCommandCenter 回调。

可能是什么原因?

我设置远程指挥中心的代码:

func setupRemoteCommandCenterTargets() {                        
        
        let commandCenter = MPRemoteCommandCenter.shared()
                                                
        commandCenter.playCommand.isEnabled = true
        commandCenter.playCommand.addTarget {event in
            
            //myPlayer.play()
            return .success
        }
        
        commandCenter.pauseCommand.isEnabled = true
        commandCenter.pauseCommand.addTarget {event in
            
            //myPlayer.pause()
            return .success
        }
                
        commandCenter.nextTrackCommand.isEnabled = true
        commandCenter.nextTrackCommand.addTarget {event in
            //myPlayer.next()
            return .success
        }
                
        commandCenter.previousTrackCommand.isEnabled = true
        commandCenter.previousTrackCommand.addTarget {event in
            //myPlayer.prev()
            return .success
        }
    }

主机上的按钮似乎被禁用,并且没有调用 MPRemoteCommandCenter 回调中的任何按钮。

标签: iosswiftcarplay

解决方案


推荐阅读