Merge pull request #1016 from KaiStarkk/hotfix-pr-1005

[Fix] Prevent crash from force unwrapping nil value in PR-1005
This commit is contained in:
advplyr 2023-12-31 16:06:50 -06:00 committed by GitHub
commit 56bc569d4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -583,30 +583,33 @@ class AudioPlayer: NSObject {
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget { [weak self] event in
if (self!.isPlaying()) {
self?.pause()
guard let strongSelf = self else { return .commandFailed }
if strongSelf.isPlaying() {
strongSelf.pause()
} else {
self?.play(allowSeekBack: true)
strongSelf.play(allowSeekBack: true)
}
return .success
}
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget { [weak self] event in
if (self!.isPlaying()) {
self?.pause()
guard let strongSelf = self else { return .commandFailed }
if strongSelf.isPlaying() {
strongSelf.pause()
} else {
self?.play(allowSeekBack: true)
strongSelf.play(allowSeekBack: true)
}
return .success
}
commandCenter.togglePlayPauseCommand.isEnabled = true
commandCenter.togglePlayPauseCommand.addTarget { [weak self] event in
if (self!.isPlaying()) {
self?.pause()
guard let strongSelf = self else { return .commandFailed }
if strongSelf.isPlaying() {
strongSelf.pause()
} else {
self?.play(allowSeekBack: true)
strongSelf.play(allowSeekBack: true)
}
return .success
}