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?

idearibosome
  • 684
  • 1
  • 7
  • 17
  • I am facing a similar problem. If your issue is resolved then can you plz answer my this question -> http://stackoverflow.com/questions/20089021/lock-screen-players-seek-bar-issue-in-ios-7/20142141?noredirect=1#20142141 – iVipS Nov 25 '13 at 05:48
  • 1
    @iVipS 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. – idearibosome Dec 01 '13 at 07:30
  • I found solution for playback position slider over here https://stackoverflow.com/a/48890827/9359678 hope this will help – Yaroslav Luchyt Feb 20 '18 at 17:29
  • @YaroslavLuchyt Yes, the changePlaybackPositionCommand property has been available since iOS 9.1. – idearibosome Feb 21 '18 at 05:53

3 Answers3

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];
Itachi
  • 5,777
  • 2
  • 37
  • 69
ren6
  • 564
  • 3
  • 8
  • 3
    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. – Rahul Mathur Apr 01 '14 at 07:48
  • even I am struggling with forward and backward seeking...another thing is, what is the expected type or format of MPMediaItemPropertyPlaybackDuration key... – MPG Oct 24 '14 at 19:27
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.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
3

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.

xyz
  • 115
  • 3