How to enable audio scrubber in iOS Lock Screen control panel?
Asked Answered
M

3

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

Murtha answered 22/9, 2013 at 7:7 Comment(7)
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.Growth
Have you figured out how to do this (scrubber)?Bohemia
@Growth no.. just adding [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; in viewDidAppear seems to work for meMurtha
@Bohemia nope :| You are looking for the same?Murtha
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.Growth
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 << and >> buttons? I've got them working! :DAmarillo
@AshishAwaghad did you managed to find out yet ?Macnamara
D
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

Diazole answered 3/1, 2014 at 17:59 Comment(4)
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. itunes.apple.com/au/app/habu-music/id540535146?mt=8Macnamara
@Macnamara 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.Diazole
HI @lap.flix, you are right, i checked the app and other app like spotify, they are using different controller.Macnamara
@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)Diazole
C
3

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

See my answer

Centistere answered 16/10, 2016 at 21:55 Comment(0)
M
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
    }
Mccain answered 20/6, 2019 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.