音频播放锁定屏幕控件未在iPhone上显示 [英] Audio playback lock screen controls not displaying on iPhone

查看:855
本文介绍了音频播放锁定屏幕控件未在iPhone上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实际的iPhone 6s设备上使用iOS 10.2对此进行测试.

I am testing this using iOS 10.2 on my actual iPhone 6s device.

我正在播放流音频,并且能够播放/暂停音频,跳过曲目等.我还启用了背景模式,并且音频在后台播放,并正确地在播放列表中继续播放.我唯一遇到的问题是显示锁定屏幕控件.什么都没显示...

I am playing streamed audio and am able to play/pause audio, skip tracks, etc. I also have enabled background modes and the audio plays in the background and continues through a playlist properly. The only issue I am having is getting the lock screen controls to show up. Nothing displays at all...

在MainViewController的viewDidLoad()中,当我的应用程序启动时,我将其称为...

In viewDidLoad() of my MainViewController, right when my app launches, I call this...

 func setupAudioSession(){

   UIApplication.shared.beginReceivingRemoteControlEvents()


   do {
       try    AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions.mixWithOthers)

       self.becomeFirstResponder()

       do {
           try AVAudioSession.sharedInstance().setActive(true)
                   print("AVAudioSession is Active")
       } catch let error as NSError {
                   print(error.localizedDescription)

       }
   } catch let error as NSError {
               print(error.localizedDescription)
   }
}

然后在开始播放音频后在我的AudioPlayer类中调用...

and then in my AudioPlayer class after I begin playing audio I call ...

func setupLockScreen(){
       let commandCenter = MPRemoteCommandCenter.shared()
       commandCenter.nextTrackCommand.isEnabled = true
       commandCenter.nextTrackCommand.addTarget(self, action:#selector(skipTrack))
       MPNowPlayingInfoCenter.default().nowPlayingInfo = [MPMediaItemPropertyTitle: "TESTING"]
}

当我锁定iPhone并再次点击电源按钮以进入锁定屏幕时,根本不会显示音频控件.好像没有声音在播放,我只看到正常的背景照片.此外,控制面板中也没有显示任何控件(在主屏幕上向上滑动,然后向左滑动至音乐控件应位于的位置).

When I lock my iPhone and then tap the power button again to go to the lock screen, the audio controls are not displayed at all. It is as if no audio is playing, I just see my normal background photo. Also no controls are displayed in the control panel (swiping up on home screen and then swiping left to where the music controls should be).

这是因为我没有使用AVAudioPlayer或AVPlayer吗?但是,例如,Spotify如何使锁定屏幕控件使用自己的自定义音频播放器显示呢?感谢您的任何建议/帮助

Is the issue because I am not using AVAudioPlayer or AVPlayer? But then how does, for example, Spotify get the lock screen controls to display using their own custom audio player? Thanks for any advice / help

推荐答案

问题竟然是此行...

The issue turned out to be this line...

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions.duckOthers)

一旦我将其更改为

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [])

一切正常.因此,似乎传入任何AVAudioSessionCategoryPlaybackOptions参数都会导致锁定屏幕控件无法显示.我还尝试传入.mixWithOthers,这也导致锁定屏幕控件无法显示

everything worked fine. So it seems that passing in any argument for AVAudioSessionCategoryPlaybackOptions causes the lock screen controls to not display. I also tried passing in .mixWithOthers an that too caused the lock screen controls to not be displayed

这篇关于音频播放锁定屏幕控件未在iPhone上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆