From 09a372bc45fde16fd42257ab6f78b8deeecf720b Mon Sep 17 00:00:00 2001
From: 杨锴 <841720330@qq.com>
Date: 星期三, 16 四月 2025 16:38:05 +0800
Subject: [PATCH] fix bug

---
 XQMuse/Root/PayMusicView/PayMusicVC.swift |   42 +++++++++++++++++++++++-------------------
 1 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/XQMuse/Root/PayMusicView/PayMusicVC.swift b/XQMuse/Root/PayMusicView/PayMusicVC.swift
index da1beae..abcf9b3 100644
--- a/XQMuse/Root/PayMusicView/PayMusicVC.swift
+++ b/XQMuse/Root/PayMusicView/PayMusicVC.swift
@@ -507,27 +507,27 @@
 
 				/// 播放场景音乐
 				func playSceneAt(_ url:String){
-        guard let URL = URL(string: url.jq_urlEncoded()) else { return }
-								scenePlayer?.pause()
+        checkCacheAudio(from: URL(string: url.jq_urlEncoded())!) {[weak self] state, url in
+            guard let weakSelf = self else { return }
+            weakSelf.scenePlayer?.pause()
 
-								if scenePlayer == nil{
-												scenePlayer = AVPlayer(url: URL)
-								}else{
-												scenePlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL))
-								}
+            if weakSelf.scenePlayer == nil{
+                weakSelf.scenePlayer = AVPlayer(url: url)
+            }else{
+                weakSelf.scenePlayer?.replaceCurrentItem(with: AVPlayerItem(url: url))
+            }
 
-        do {
-            try AVAudioSession.sharedInstance().setActive(false)
-            try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default, options: [])
-        } catch {
-            print(error)
+            do {
+                try AVAudioSession.sharedInstance().setActive(false)
+                try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default, options: [])
+            } catch {
+                print(error)
+            }
+
+            DispatchQueue.main.asyncAfter(delay: 0.5) {
+                weakSelf.scenePlayer?.play()
+            }
         }
-
-        DispatchQueue.main.asyncAfter(delay: 0.5) {
-												self.scenePlayer?.play()
-//            self.scenePlayer?.allowsExternalPlayback = false
-//            self.scenePlayer?.usesExternalPlaybackWhileExternalScreenIsActive = false
-								}
 				}
 
 				func dellocScene(){
@@ -651,14 +651,18 @@
 
 								// 检查缓存中是否已存在文件
 								if FileManager.default.fileExists(atPath: videoCacheUrl.path) {
+            print("启用缓存")
 												completion(true,videoCacheUrl)
 												return
 								}else{
 												completion(false,url)
+            print("没有缓存:执行下载")
 								}
 
 								// 使用URLSession下载视频
-								let downloadTask = session.downloadTask(with: url) { tempLocalUrl, response, error in
+								let downloadTask = session.downloadTask(with: url) {
+            tempLocalUrl, response, error in
+            print("执行下载任务")
 												if let tempLocalUrl = tempLocalUrl, error == nil {
 																do {
 																				let temp = videoCacheUrl

--
Gitblit v1.7.1