idearibosome idearibosome - 1 year ago 130
iOS Question

How to set current playback duration and elapsed time on iOS 7 lockscreen?

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?

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download