AudioPlayer
AudioPlayer copied to clipboard
Why I can't seek in lock screen?
I can't seek in MPNowPlayingInfoCenter, I see only progress line. Anybody know what a problem is?
Use MPNowPlayingInfoCenter
with your own code
@Rusik could you share the param that make the seek (using the slider control, like Itunes does)?
@jadsonlourenco use something like
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.changePlaybackPositionCommand.isEnabled = true
commandCenter.changePlaybackPositionCommand.addTarget { event -> MPRemoteCommandHandlerStatus in
let event = event as! MPChangePlaybackPositionCommandEvent
self.seekTo(event.positionTime)
return .success
}
Thanks @Rusik. I don't think this should be part of the player, mostly because some people might want to handle things differently. What do you guys think?
You are already using MPNowPlayingInfoCenter
so maybe this could be an optional feature enabled by default. With implementation for common cases like play/pause, next/prev track and seek.
The only difference is that MPNowPlayingInfoCenter
is just displaying things provided by the developer, whereas MPRemoteCommandCenter
also handles the actions. That’s kind of what stopped me from adding it until now.
how to disable next/previous track buttons using command center with the player ?
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.previousTrackCommand.isEnabled = false
commandCenter.nextTrackCommand.isEnabled = false
doesn't work.
This work for me
override func remoteControlReceived(with event: UIEvent?) {
if let event = event {
switch event.subtype {
case .remoteControlBeginSeekingBackward:
print("Event:0")
case .remoteControlBeginSeekingForward:
print("Event:1")
case .remoteControlEndSeekingBackward:
print("Event:2")
case .remoteControlEndSeekingForward:
print("Event:3")
case .remoteControlNextTrack:
print("Event:4")
case .remoteControlPause,
.remoteControlTogglePlayPause:
print("Event:5")
/*case .remoteControlPlay,
.remoteControlTogglePlayPause
print("Event:6")*/
player.remoteControlReceived(with: event)
case .remoteControlPreviousTrack:
print("Event:7")
case .remoteControlStop:
print("Event:8")
default:
player.remoteControlReceived(with: event)
break
}
print(event)
print(event.type)
}
}