播放/暂停下一个/上一个按钮在控制中心显示为灰色 [英] Play/Pause next/Prev buttons are greyed out in control center

查看:303
本文介绍了播放/暂停下一个/上一个按钮在控制中心显示为灰色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,从控制中心控制播放。
当在AVPlayer中进行播放时(此时播放控件在控制中心正常工作),我正在加载带有其他流媒体URL的webview。

In my application, playback is controlled from control center. When playback is going on in AVPlayer(At this time playback controls are working fine from control center), I am loading a webview with other streaming URL.

再次完成流式传输后,我将从AVPlayer开始播放。
此后,Playback控件在控制中心显示为灰色。

Once streaming is done again I am starting playback from AVPlayer. After this, Playback controls are greyed out in control center.

我正在使用 [MPNowPlayingInfoCenter defaultCenter] .nowPlayingInfo 在控制中心启用播放控制。

I am using [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo to enable playback control in control center.

会出现什么问题?

推荐答案

我遇到了这个问题以及使用 AVPlayer 实例。您可以使用 MPRemoteCommandCenter 在锁定屏幕和命令中心设置控件。

I ran into this problem as well working with an AVPlayer instance. You can use MPRemoteCommandCenter to set up controls on the lock screen and command center.

MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];

commandCenter.previousTrackCommand.enabled = YES;
[commandCenter.previousTrackCommand addTarget:self action:@selector(previousTapped:)];

commandCenter.playCommand.enabled = YES;
[commandCenter.playCommand addTarget:self action:@selector(playAudio)];

commandCenter.pauseCommand.enabled = YES;
[commandCenter.pauseCommand addTarget:self action:@selector(pauseAudio)];

commandCenter.nextTrackCommand.enabled = YES;
[commandCenter.nextTrackCommand addTarget:self action:@selector(nextTapped:)];

previousTapped: playAudio pauseAudio nextTapped 是我的视图控制器中的所有方法,分别调用控制我的 AVPlayer 实例的方法。要启用操作,您必须明确将启用设置为 YES 提供命令一个目标选择器

previousTapped:, playAudio, pauseAudio, and nextTapped are all methods in my view controller that call respective methods to control my AVPlayer instance. To enable an action, you must explicitly set enabled to YES and provide a command with a target and selector.

如果你需要禁用特定操作,您必须明确将已启用属性设置为 以及添加目标。

If you need to disable a specific action, you must explicitly set the enabled property to NO in addition to adding a target.

commandCenter.previousTrackCommand.enabled = NO;
[commandCenter.previousTrackCommand addTarget:self action:@selector(previousTapped:)];

如果你没有设置启用命令,该项目将不会出现在锁定屏幕或命令中心。

If you do not set enabled for the command, the item will not appear at all on the lock screen or in command center.

此外,请记住将应用程序设置为后台播放(添加 UIBackgroundModes audio 您的Info.plist文件的值。),将播放器设置为活动状态,并检查错误:

In addition, remember to set your app up for background playback (add the UIBackgroundModes audio value to your Info.plist file.), set the player active, and check for errors:

NSError *setCategoryError;
NSError *setActiveError;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
[[AVAudioSession sharedInstance] setActive:YES error:&setActiveError];

这篇关于播放/暂停下一个/上一个按钮在控制中心显示为灰色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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