相关疑难解决方法(0)

播放/暂停和已用时间未在iOS命令中心正确更新

我有一个可以从iOS命令中心和锁定屏幕播放的视频播放器.当我在我的应用程序切换播放/暂停按钮,它应该更新指挥中心(播放/暂停按钮,MPRemoteCommandCenter通过更新)nowPlayingInfo(MPNowPlayingInfoCenter).我不确定为什么它没有更新.

例如,如果我在我的应用程序中使用自定义按钮暂停视频,则命令中心仍会显示暂停按钮(意味着视频仍在播放,这是错误的.)

在此输入图像描述

这是我更新的方式nowPlayingInfo:

func updateMPNowPlayingInforCenterMetadata() {
    guard video != nil else {
        nowPlayingInfoCenter.nowPlayingInfo = nil
        return
    }

    var nowPlayingInfo = nowPlayingInfoCenter.nowPlayingInfo ?? [String: Any]()

    let image: UIImage
    if let placeholderLocalURL = video.placeholderLocalURL, let placeholderImage = UIImage(contentsOfFile: placeholderLocalURL.path) {
        image = placeholderImage
    } else {
        image = UIImage()
    }

    let artwork = MPMediaItemArtwork(boundsSize: image.size, requestHandler: { _ -> UIImage in
        return image
    })

    nowPlayingInfo[MPMediaItemPropertyTitle] = video.title
    nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = video.creator?.name ?? " "
    nowPlayingInfo[MPMediaItemPropertyArtwork] …
Run Code Online (Sandbox Code Playgroud)

objective-c mpmediaitem ios mpnowplayinginfocenter swift

13
推荐指数
1
解决办法
2674
查看次数