Starting from iOS 5, every music player can set current playing music information such as title, artist, album title, and artwork on [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo to show on lock screen.
On iOS 7, playback position slider, duration, and elapsed time information are added to both lock screen and control center. However, I cannot find any documents to set these kinds of information and enable the slider to change playback position.
Is there any way to solve this problem?
You need to setup playback rate to 1.0f even if documentation says it's 1.0 by default.
NSDictionary *mediaInfo = @{
MPMediaItemPropertyTitle: audio.title,
MPMediaItemPropertyArtist: audio.artist,
MPMediaItemPropertyPlaybackDuration: audio.duration,
MPNowPlayingInfoPropertyPlaybackRate: @(1.0)
};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
They're all documented in the reference for MPNowPlayingInfoCenter
. The currently playing properties are optional values that may or may not be set. The link to that is in the sentence at the end of the list of normal playing properties:
Additional properties you can set are described in this document in “Additional Metadata Properties.”. (emphasis mine)
The properties that you are interested in are: MPNowPlayingInfoPropertyElapsedPlaybackTime
and MPMediaItemPropertyPlaybackDuration
.
This information is all publicly available, and as the iOS 7 SDK does not seem to be published yet (as of 2013-09-14), I presume it was available prior to that version of iOS as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With