Play/Pause next/Prev buttons are greyed out in control center
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.
Once streaming is done again I am starting playback from AVPlayer.
After this, Playback controls are greyed out in control center.
I am using
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo to enable playback control in control center.
What would be the problem?
- iOS: Updating Media Information in the Background
- Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?
- AVAudioPlayer on Lock Screen
- MPMediaItemArtwork init(image:) deprecated in iOS 10.0
- Reading MP3 information using objective c
- Change lock screen background audio controls text?
3 Solutions Collect From Internet About “Play/Pause next/Prev buttons are greyed out in control center”
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:)];
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
YES and provide a command with a
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.
In addition, remember to set your app up for background playback (add the
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];
Google brought me here because I was having an issue with the command center when using AdMob video ads, and a comment on the OP referenced AdMob. Posting here for anyone else also having these issues.
AdMob video ads on iOS seem to utilize the
MPRemoteCommandCenter for whatever reason. This may interfere with your app’s usage of the command center. Here’s what I came up with as a potential workaround to this: https://gist.github.com/ekilah/e74683291d3e7fafb947
The “gist” of the workaround is to reset all of the
sharedCommandCenters listeners and the
MPNowPlayingInfoCenter‘s info dictionary after an ad from AdMob is fetched and after it’s played. The way the workaround goes about resetting all of the commands is less than pretty, but this is what I came up with. Maybe someone has a better method?
This approach may also help the OP. Resetting things between different usages may be a solution.
Finally I solved this problem by loading the mp3 url using AVplayer instead of loading it in UIWebview. Current playback time, total time can be retrieved from AVPlayer and also it is possible to seek the playback using slider.
- help me to parse JSON value using JSONTouch
- iOS8: UIDocumentPickerViewController get NSData
- why is this causing so much trouble? (protocols and typealiases on their associated types)
- How to convert date string into format “17 Nov 2010”
- Auto synthesis error in AFURLRequestSerialization with Xcode 6
- How to replicate hash_hmac('sha256', $key, $secret_key) function in Swift 4?
- NSTimer not fired when uiscrollview event occurs
- iOS – Push viewController from code and storyboard
- Modifying an array of dictionaries in Swift
- Missing Compliance in Status when i add built for internal testing in Test Flight.How to solve?
- h.264 video won't play on iOS
- How to create a string with format?
- callback from c++ to objective c
- Latest Google Plus iOS SDK 1.7.1 not supporting architecture x86_64
- How to generate an end screen when two images collide?