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