Post not yet marked as solved
Post marked as unsolved with 0 replies, 534 views
private func updateNowPlayingInfo() {
var nowPlayingInfo = [String: Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = songLabel.text
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = Int(Double(audioLengthSamples) / audioSampleRate)
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = Int(Double(currentPosition) / audioSampleRate)
print(isPlaying)
print("updateNow")
let playbackRate = isPlaying ? self.timeEffect.rate : 0.0
print(playbackRate)
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = playbackRate
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
Whenever I press my play/pause button in the app, I expect control center and the lock screen to reflect this. However, control center symbols stays as pause regardless of what I do in the app.
Am I missing anything? Running on device with iOS 16.4.1.
private func configureRemoteCommandCenter() {
let commandCenter = MPRemoteCommandCenter.shared()
// Play command
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget { [weak self] event in
// Handle the play command
self?.playOrPauseFunction()
return .success
}
// Pause command
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget { [weak self] event in
// Handle the pause command
self?.playOrPauseFunction()
return .success
}
commandCenter.togglePlayPauseCommand.isEnabled = true
commandCenter.togglePlayPauseCommand.addTarget { [weak self] event in
self?.playOrPauseFunction()
return .success
}
commandCenter.changePlaybackRateCommand.isEnabled = true
commandCenter.changePlaybackPositionCommand.isEnabled = true
commandCenter.changePlaybackPositionCommand.addTarget { [unowned self] event in
guard let event = event as? MPChangePlaybackPositionCommandEvent else {
return .commandFailed
}
currentPosition = AVAudioFramePosition(event.positionTime * audioSampleRate)
scrubSeek(to: Double(currentPosition))
updateNowPlayingInfo()
return .success
}
// Add handlers for other remote control events here...
}