| | |
| | | import JQTools |
| | | import AVFoundation |
| | | import MediaPlayer |
| | | import RxRelay |
| | | |
| | | class PayMusicVC: BaseVC { |
| | | |
| | |
| | | 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 { |
| | |
| | | player?.play() |
| | | } |
| | | |
| | | |
| | | func setLockScreen(){ |
| | | // 锁屏进度控制 |
| | | let center = MPRemoteCommandCenter.shared() |
| | |
| | | } |
| | | } |
| | | |
| | | 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) { |