13

I have the following dictionary for MPNowPlayingInfoCenter

@{MPMediaItemPropertyAlbumTitle: @"First Title",
                                MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"Album-Cover.jpg"]],
                                MPMediaItemPropertyPlaybackDuration:[NSNumber numberWithDouble:self.storyAudioPlayer.duration],
                                MPNowPlayingInfoPropertyElapsedPlaybackTime:[NSNumber numberWithDouble:self.storyAudioPlayer.currentTime],
                                MPNowPlayingInfoPropertyPlaybackRate:@1.0
                                }

Everything else is working fine but I can't seek songs using the slider. As shown in the image. What parameter am I missing?

Lock screen screenshot

Ashish Awaghad
  • 2,822
  • 3
  • 22
  • 33
  • Was there a trick you had to do to get the buttons to work in iOS 7? The double-tap-home-audio-controls work fine for me in iOS 6, but the Control Center buttons don't send events to my app in iOS 7. There's a thread on the developer forums where people are saying this seems to be an iOS 7 bug. Thanks. – Tenfour04 Sep 24 '13 at 01:27
  • Have you figured out how to do this (scrubber)? – SG1 Sep 26 '13 at 21:37
  • @Tenfour04 no.. just adding [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; in viewDidAppear seems to work for me – Ashish Awaghad Sep 28 '13 at 09:14
  • @SG1 nope :| You are looking for the same? – Ashish Awaghad Sep 28 '13 at 09:19
  • Actually, I found that it only doesn't work on my Verizon iPhone 5. It doesn't work for any third party apps on that phone. Works fine on all my other test devices. I have a feeling that this scrubber has not been enabled for third-party apps, since nothing related to it has been added to the constants for the remote control events. – Tenfour04 Sep 28 '13 at 16:23
  • I have another (possibly dumb!) question: I'm using `AVAudioPlayer` and I've implemented the remote controls with `UIEventTypeRemoteControl`. Do I have to use `MPNowPlayingInfoCenter` to display the duration and title? Also, for seeking the time, are you happy to use those two `<>` buttons? I've got them working! :D – Neeku Dec 03 '13 at 21:45
  • @AshishAwaghad did you managed to find out yet ? – Desmond Jan 11 '14 at 14:06

3 Answers3

3

You can't. You could file a bug report to Apple so that they implement it someday.

EDIT: It's now possible to do it since iOS 9

Felix Lapalme
  • 1,037
  • 1
  • 11
  • 25
  • 2
    no u can, there is an 3rd party app called HABU that allows you to seek. I am also looking for answer on how to do it. https://itunes.apple.com/au/app/habu-music/id540535146?mt=8 – Desmond Jan 11 '14 at 14:05
  • 2
    @Desmond that app is using the Music app to play its music. It's a completely different thing and the music needs to already be in the library. – Felix Lapalme Jan 17 '14 at 22:17
  • HI @lap.flix, you are right, i checked the app and other app like spotify, they are using different controller. – Desmond Jan 19 '14 at 23:47
  • @desmond If it's important for you you could fill a feature request on Apple's bug reporter tool. The more duplicates they get the more priority you get (it's a weird system but that,s how they roll and it's sort of logic) – Felix Lapalme Jan 20 '14 at 03:22
3

You can do it on iOS 9.1 and higher with help of MPRemoteCommandCenter and changePlaybackPositionCommand.

See my answer

Community
  • 1
  • 1
Neiman Aleksei
  • 835
  • 1
  • 8
  • 12
3

Swift 5

You can do it with MPRemoteCommandCenter.changePlaybackPositionCommand.

The command object for changing the playback position in a media item.

let commandCenter = MPRemoteCommandCenter.shared()
    commandCenter.changePlaybackPositionCommand.isEnabled = true
    commandCenter.changePlaybackPositionCommand.addTarget { event in
        if let event = event as? MPChangePlaybackPositionCommandEvent {
            let time = CMTime(seconds: event.positionTime, preferredTimescale: 1000000)
            self.avplayer.seekTo(time)
        }
        return .success
    }
goofy
  • 155
  • 2
  • 10