|
@@ -40,25 +40,27 @@ class TSBusinessAudioPlayer {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- var isStop:Bool = false
|
|
|
-
|
|
|
+ private var isStop:Bool = false
|
|
|
+ private var loadingLogic:(show: () -> Void, hide: () -> Void)?
|
|
|
init(stateChangeBlock:@escaping (PlayerState) -> Void) {
|
|
|
self.stateChangeBlock = stateChangeBlock
|
|
|
}
|
|
|
|
|
|
func playRingtone(ringtone:String?) {
|
|
|
if let ringtone = ringtone {
|
|
|
- let loadingLogic = kCreateLoadingLogic {
|
|
|
+ loadingLogic = kCreateLoadingLogic { [weak self] in
|
|
|
+ guard let self = self else { return }
|
|
|
self.stateChangeBlock(.loading(0.0))
|
|
|
- } hideBlock: {
|
|
|
+ } hideBlock: {[weak self] in
|
|
|
+ guard let self = self else { return }
|
|
|
self.stateChangeBlock(.loading(1.0))
|
|
|
}
|
|
|
|
|
|
- loadingLogic.show()
|
|
|
+ loadingLogic?.show()
|
|
|
isStop = false
|
|
|
TSCommonTool.downloadAndCacheFile(from: ringtone) { [weak self] path, error in
|
|
|
guard let self = self else { return }
|
|
|
- loadingLogic.hide()
|
|
|
+ loadingLogic?.hide()
|
|
|
|
|
|
if isStop == true{
|
|
|
self.stop()
|
|
@@ -91,11 +93,13 @@ class TSBusinessAudioPlayer {
|
|
|
|
|
|
func stop() {
|
|
|
isStop = true
|
|
|
+ loadingLogic?.hide()
|
|
|
self.audioPlayer?.stop()
|
|
|
stateChangeBlock(.stop)
|
|
|
}
|
|
|
|
|
|
func pause() {
|
|
|
+ loadingLogic?.hide()
|
|
|
self.audioPlayer?.pause()
|
|
|
stateChangeBlock(.pause)
|
|
|
}
|