|
@@ -32,7 +32,7 @@ class TSBusinessAudioPlayer {
|
|
|
}
|
|
|
return 0.0
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var isPlaying:Bool{
|
|
|
if let audioPlayer = audioPlayer {
|
|
|
return audioPlayer.isPlaying
|
|
@@ -40,7 +40,17 @@ class TSBusinessAudioPlayer {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- private var isStop:Bool = false
|
|
|
+
|
|
|
+ //播放器是否可用
|
|
|
+ var playerUsable:Bool {
|
|
|
+ if let audioPlayer = audioPlayer {
|
|
|
+ return audioPlayer.playerUsable
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ //加载音乐可能 2-3 秒有结果,停止加载后播放.
|
|
|
+ private var isStopPlayingAfterLoading:Bool = false
|
|
|
private var loadingLogic:(show: () -> Void, hide: () -> Void)?
|
|
|
init(stateChangeBlock:@escaping (PlayerState) -> Void) {
|
|
|
self.stateChangeBlock = stateChangeBlock
|
|
@@ -57,13 +67,14 @@ class TSBusinessAudioPlayer {
|
|
|
}
|
|
|
|
|
|
loadingLogic?.show()
|
|
|
- isStop = false
|
|
|
+ isStopPlayingAfterLoading = false
|
|
|
TSCommonTool.downloadAndCacheFile(from: ringtone) { [weak self] path, error in
|
|
|
guard let self = self else { return }
|
|
|
loadingLogic?.hide()
|
|
|
|
|
|
- if isStop == true{
|
|
|
+ if isStopPlayingAfterLoading == true{
|
|
|
self.stop()
|
|
|
+ isStopPlayingAfterLoading = false
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -92,13 +103,14 @@ class TSBusinessAudioPlayer {
|
|
|
}
|
|
|
|
|
|
func stop() {
|
|
|
- isStop = true
|
|
|
+ isStopPlayingAfterLoading = true
|
|
|
loadingLogic?.hide()
|
|
|
self.audioPlayer?.stop()
|
|
|
stateChangeBlock(.stop)
|
|
|
}
|
|
|
|
|
|
func pause() {
|
|
|
+ isStopPlayingAfterLoading = true
|
|
|
loadingLogic?.hide()
|
|
|
self.audioPlayer?.pause()
|
|
|
stateChangeBlock(.pause)
|