Xcode - Mpnowplayinginfocenter Info Is Not Displayed on iOS 8

xcode - MPNowPlayingInfoCenter info is not displayed on iOS 8

The problem is that you are not satisfying the requirements to become master of the lock screen and control center, as I explain in my book. You should be seeing the modern (iOS 8) equivalent of this:

Sample Image

The fact that you are not seeing it suggests that you are omitting one or more of the requirements, which I list (quoting directly from my book here):

  • Your app must contain a UIResponder in its responder chain that
    returns YES from canBecomeFirstResponder, and that responder must
    actually be first responder.
  • Some UIResponder in the responder chain,
    at or above the first responder, must implement
    remoteControlReceivedWithEvent:.
  • Your app must call the UIApplication
    instance method beginReceivingRemoteControlEvents.
  • Your app’s audio
    session’s policy must be Playback.
  • Your app must be emitting some sound.

I don't know which of those you are omitting; it could be more than one. You might like to compare your code with a working example, here:

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/iOS7bookExamples/bk2ch14p653backgroundPlayerAndInterrupter/backgroundPlayer/
backgroundPlayer/ViewController.m

iOS MPNowPlayingInfoCenter not Displaying Using AVPlayer and AVAudioSession

Okay, I solved it. My app was fine; the issue was that the simulator wasn't acting like an actual device. When I tested it on an actual iPad, the lock screen info displayed perfectly. It still doesn't display on the simulator, though. Thank you for your time.

MPNowPlayingInfoCenter is not showing but background playing does work

I solved it by adding

func setupNowPlayingInfoCenter(){
UIApplication.shared.beginReceivingRemoteControlEvents()
MPRemoteCommandCenter.shared().playCommand.addTarget {event in
self.play()
return .success
}
MPRemoteCommandCenter.shared().pauseCommand.addTarget {event in
self.pause()
return .success
}
MPRemoteCommandCenter.shared().nextTrackCommand.addTarget {event in
self.goForward()
return .success
}
MPRemoteCommandCenter.shared().previousTrackCommand.addTarget {event in
self.goBackward()
return .success
}
}

MPNowPlayingInfoCenter defaultCenter will not update or retrieve information

I finally figured out the problem, I was not prompting my app to receive remote control events, simply adding this line fixed the problem:

 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

How to Set Artwork Image for MPNowPlayingInfoCenter

Just in case anyone finds this question and was going crazy like myself, I was able to set the image by correctly resizing my UIImage to the incoming size parameter given to the MPMediaItemArtwork callback function. As it says in the docs:

The request handler returns an image in the newly requested size.
The requested size must be less than the boundsSize parameter.

Then setting my image to the incoming size parameter with the following extension, the MPMediaItemPropertyArtwork was finally successfully set.

extension UIImage {
func imageWith(newSize: CGSize) -> UIImage {
let renderer = UIGraphicsImageRenderer(size: newSize)
let image = renderer.image { _ in
self.draw(in: CGRect.init(origin: CGPoint.zero, size: newSize))
}
return image.withRenderingMode(self.renderingMode)
}
}

if let image = UIImage(named: "image_here") {
nowPlayingInfo[MPMediaItemPropertyArtwork] =
MPMediaItemArtwork(boundsSize: image.size) { size in
// Extension used here to return newly sized image
return image.imageWith(newSize: size)
}
}

MPNowPlayingInfoCenter doesn't update any information when after assigning to nowPlayingInfo

It does work, and you don't need all that glop about the first responder and so on, as you can readily prove to yourself by just going ahead and setting the now playing info and nothing else:

Sample Image

So why isn't it working for you? Probably because you are using some sort of player (such as AVPlayerViewController) that sets the now playing info itself in some way, and thus overrides your settings.



Related Topics



Leave a reply



Submit