From 50260473dbb1bf4596f9f6ead4a265ca7ee4d5b3 Mon Sep 17 00:00:00 2001
From: 杨锴 <841720330@qq.com>
Date: 星期五, 30 八月 2024 14:36:56 +0800
Subject: [PATCH] fix UI

---
 XQMuse/Root/PayMusicView/PayMusicVC.swift |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/XQMuse/Root/PayMusicView/PayMusicVC.swift b/XQMuse/Root/PayMusicView/PayMusicVC.swift
index 97c6a48..b57156c 100644
--- a/XQMuse/Root/PayMusicView/PayMusicVC.swift
+++ b/XQMuse/Root/PayMusicView/PayMusicVC.swift
@@ -9,6 +9,7 @@
 import JQTools
 import AVFoundation
 import MediaPlayer
+import RxRelay
 
 class PayMusicVC: BaseVC {
 
@@ -111,7 +112,8 @@
 				private var cacheDirectory:URL!
 				private let session = URLSession.shared
 				private var urls = [URL]()
-
+				private var timer:Timer?
+				private(set) var times = BehaviorRelay<Int?>(value: nil)
 				private static var _sharedInstance: AudioPlayer?
 
 				class func getSharedInstance() -> AudioPlayer {
@@ -203,7 +205,6 @@
 								player?.play()
 				}
 
-
 				func setLockScreen(){
 								// 锁屏进度控制
 								let center = MPRemoteCommandCenter.shared()
@@ -249,6 +250,30 @@
 								}
 				}
 
+				func setTimer(times:Int){
+								self.times.accept(times)
+								guard timer == nil else {return}
+								timer = Timer(timeInterval: 1, repeats: true, block: {[weak self] timer in
+												guard let weakSelf = self else { return }
+												let newTimes = weakSelf.times.value! - 1
+
+												if newTimes <= 0{
+																weakSelf.times.accept(nil)
+																weakSelf.stopTimer()
+												}else{
+																weakSelf.times.accept(newTimes)
+												}
+								})
+								timer?.fire()
+								RunLoop.current.add(timer!, forMode: .default)
+				}
+
+				func stopTimer(){
+								timer?.invalidate()
+								timer = nil
+								times.accept(nil)
+				}
+
 
 				// 下载视频并缓存,如果没有缓存,原路返回并异步下载
 			internal	func checkCacheAudio(from url: URL, completion: @escaping (Bool,URL) -> Void) {

--
Gitblit v1.7.1