Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

iphone

ios7

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?

like image 249
idearibosome Avatar asked Sep 14 '13 10:09

idearibosome


Video Answer


2 Answers

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];
like image 123
ren6 Avatar answered Nov 16 '22 01:11

ren6


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.

like image 24
Petesh Avatar answered Nov 16 '22 01:11

Petesh