同步修改bug
This commit is contained in:
parent
c96a1cdc5b
commit
254a3a43ac
@ -58,6 +58,8 @@ class SPPlayer: NSObject {
|
||||
weak var delegate: SPPlayerDelegate?
|
||||
|
||||
private(set) lazy var isPlaying = false
|
||||
///系统原因导致的暂停(来电话)
|
||||
private(set) lazy var systemPause = false
|
||||
private(set) lazy var playState: PlayState = .unknown
|
||||
private(set) lazy var loadState: LoadState = .unknown
|
||||
|
||||
@ -168,6 +170,7 @@ class SPPlayer: NSObject {
|
||||
}
|
||||
|
||||
func start() {
|
||||
self.systemPause = false
|
||||
self.isPlaying = true
|
||||
// if self.interruptionType != .began {
|
||||
// }
|
||||
@ -224,7 +227,7 @@ extension SPPlayer {
|
||||
guard let self = self else { return }
|
||||
if playState == .playStatePlaying && !isPlaying {
|
||||
self.pause()
|
||||
} else if playState == .playStatePaused, isPlaying, self.interruptionType != .began {
|
||||
} else if playState == .playStatePaused, isPlaying, !self.systemPause {
|
||||
self.start()
|
||||
}
|
||||
switch playState {
|
||||
@ -251,7 +254,7 @@ extension SPPlayer {
|
||||
guard let self = self else { return }
|
||||
if loadState == .playable && !isPlaying {
|
||||
self.pause()
|
||||
} else if loadState == .playable, isPlaying, self.player.playState != .playStatePlaying, self.interruptionType != .began {
|
||||
} else if loadState == .playable, isPlaying, self.player.playState != .playStatePlaying, !self.systemPause {
|
||||
self.start()
|
||||
}
|
||||
|
||||
@ -314,9 +317,11 @@ extension SPPlayer {
|
||||
guard let interruptionType = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt else { return }
|
||||
|
||||
self.interruptionType = AVAudioSession.InterruptionType(rawValue: interruptionType)
|
||||
if self.interruptionType == .began {
|
||||
if self.interruptionType == .began, self.isPlaying {
|
||||
self.systemPause = true
|
||||
self.player.pause()
|
||||
} else {
|
||||
} else if self.interruptionType == .ended {
|
||||
self.systemPause = false
|
||||
if self.isPlaying {
|
||||
self.player.play()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user