锁定屏幕时mp3player remoteControl按钮不出现

时间:2019-05-23 09:13:57

标签: swift xcode audio avaudioplayer

你好,“我的应用”中有一个mp3播放器,我希望当我播放歌曲和转到锁定屏幕时,它都应该像其他播放器一样出现具有播放暂停的播放器。我正在这样做,但是id没有出现任何按钮,在此代码之后

 if UIApplication.shared.responds(to: #selector(UIApplication.beginReceivingRemoteControlEvents)){
            UIApplication.shared.beginReceivingRemoteControlEvents()
            UIApplication.shared.beginBackgroundTask(expirationHandler: { () -> Void in
            })
        }

override func remoteControlReceived(with event: UIEvent?) {


        if event!.type == UIEvent.EventType.remoteControl{
            switch event!.subtype{
            case UIEventSubtype.remoteControlPlay:
               // play(self)
                break
            case UIEventSubtype.remoteControlPause:break
             //   play(self)
            case UIEventSubtype.remoteControlNextTrack:break
              //  next(self)
            case UIEventSubtype.remoteControlPreviousTrack:break
              //  previous(self)
            default:
                print("There is an issue with the control")
            }
        }
    }

0 个答案:

没有答案