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/Course/VC/CourseVCTeacherSpecialVC.swift |   72 +++++++++++++++++++++++++++++++----
 1 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/XQMuse/Root/Course/VC/CourseVCTeacherSpecialVC.swift b/XQMuse/Root/Course/VC/CourseVCTeacherSpecialVC.swift
index f5faa14..df8b29c 100644
--- a/XQMuse/Root/Course/VC/CourseVCTeacherSpecialVC.swift
+++ b/XQMuse/Root/Course/VC/CourseVCTeacherSpecialVC.swift
@@ -32,15 +32,13 @@
 								cell0!.backgroundColor = UIColor(hexString: "#f6f6f6")
 								cell1!.backgroundColor = UIColor(hexString: "#f6f6f6")
 
-								Services.tutorInfo().subscribe(onNext: { data in
-												if let m = data.data{
-																self.model = m
-																self.cell0!.setContent(title: "导师简介", content: m.tutorIntroduction)
-																self.cell1!.setItems(m.list)
-																self.tableView?.reloadData()
-                self.headerView.updateVideoUrl(m.videoUrl,autoPlay: false,placeHoderImageUrl: m.coverUrl.jq_urlEncoded(),delegate: self)
-												}
-								}).disposed(by: disposeBag)
+
+        getData()
+//        LoginSuccess_Noti
+
+        NotificationCenter.default.rx.notification(LoginSuccess_Noti).take(until: self.rx.deallocated).subscribe {[unowned self] _ in
+            self.getData()
+        }.disposed(by: disposeBag)
 
 
         self.cell0?.webView.scrollView.rx.observe(CGSize.self, "contentSize").map { (size) -> CGFloat? in
@@ -53,6 +51,23 @@
                 if height > self.cell0?.cons_webHei.constant ?? 0{
                     self.cell0?.cons_webHei.constant = height
                     self.tableView?.reloadData()
+                }
+            }
+        }).disposed(by: disposeBag)
+    }
+
+    private func getData(){
+        Services.tutorInfo().subscribe(onNext: {[weak self] data in
+            guard let weakSelf = self else { return }
+            if let m = data.data{
+                weakSelf.model = m
+                weakSelf.cell0!.setContent(title: "导师简介", content: m.tutorIntroduction)
+                weakSelf.cell1!.setItems(m.list)
+                weakSelf.tableView?.reloadData()
+                if let videoUrl = weakSelf.model?.videoUrl.jq_urlEncoded(),videoUrl.jq_isVideo{
+                    weakSelf.checkCacheAudio(from: URL(string:videoUrl)!) { state, url in
+                        weakSelf.headerView.updateVideoUrl(videoUrl,autoPlay: false,placeHoderImageUrl: m.coverUrl.jq_urlEncoded(),delegate: self)
+                    }
                 }
             }
         }).disposed(by: disposeBag)
@@ -93,6 +108,45 @@
 				override var shouldAutorotate: Bool{
 								return  true
 				}
+
+    internal func checkCacheAudio(from url: URL, completion: @escaping (Bool,URL) -> Void) {
+
+        let cacheDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("Masters")
+
+        let videoCacheUrl = cacheDirectory.appendingPathComponent(url.lastPathComponent.jq_md5String() + "." + url.pathExtension)
+
+        // 检查缓存中是否已存在文件
+        if FileManager.default.fileExists(atPath: videoCacheUrl.path) {
+            print("启用缓存")
+            completion(true,videoCacheUrl)
+            return
+        }else{
+            completion(false,url)
+            print("没有缓存:执行下载")
+        }
+
+        // 使用URLSession下载视频
+        let downloadTask = URLSession.shared.downloadTask(with: url) {
+            tempLocalUrl, response, error in
+            print("执行下载任务")
+            if let tempLocalUrl = tempLocalUrl, error == nil {
+                do {
+                    let temp = videoCacheUrl
+
+                    if !(FileManager.default.fileExists(atPath: cacheDirectory.path)){
+                        try FileManager.default.createDirectory(at: cacheDirectory, withIntermediateDirectories: true)
+                    }
+
+                    try FileManager.default.moveItem(at: tempLocalUrl, to: temp)
+                } catch let e {
+                    print("视频缓存失败:catch:\(e)")
+                }
+            } else {
+                print("视频缓存失败:\(error?.localizedDescription ?? "")")
+            }
+        }
+        downloadTask.resume()
+    }
 }
 extension CourseVCTeacherSpecialVC:UITableViewDataSource{
 				func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

--
Gitblit v1.7.1