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

3

19

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?

Linus answered 14/9, 2013 at 10:40 Comment(4)
I am facing a similar problem. If your issue is resolved then can you plz answer my this question -> #20089521Hemingway
@Hemingway I solved showing current playing position on lockscreen, but I also didn't find any solution to allow seeking features on my music app yet. It seems that Apple currently does not implement API about lockscreen seek bar for thrid-party apps.Linus
I found solution for playback position slider over here https://mcmap.net/q/665570/-ios-7-rewind-songs-on-lock-screen-using-avplayer hope this will helpNomenclature
@YaroslavLuchyt Yes, the changePlaybackPositionCommand property has been available since iOS 9.1.Linus
N
37

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];
Nutcracker answered 24/9, 2013 at 10:29 Comment(2)
How can i control forward and backward seeking? I need to find the amount of seek duration so that i can pass it in my audio player current duration.Fawnfawna
even I am struggling with forward and backward seeking...another thing is, what is the expected type or format of MPMediaItemPropertyPlaybackDuration key...Besiege
I
8

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.

Ideal answered 14/9, 2013 at 15:2 Comment(0)
Z
4

Just be warned: Apple's document never made this clear -- If you use MPMusicPlayerController, your music is played under the hood by the "music" app and you do NOT have any control of nowPlayingInfoCenter. And you will NOT receive remote control events generated by the user actions (such as play/pause) applied to the lock screen because those events are propagated via the nowPlayingInfoCenter to the "music" app, not to yours. When using other media players, such as AV or AvAudio, you can control the nowPlayingInfoCenter and receive the remote control events. But if you use AVAudioSessionCategoryOptions.MixWithOthers to set up the AV player, you can't control nowPlayingInfoCenter either. I wish Apple documented those details better.

Zolner answered 21/1, 2015 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.