浏览代码

视频优先取低码率

xiaohaizhao 1 月之前
父节点
当前提交
585115fd11
共有 3 个文件被更改,包括 19 次插入2 次删除
  1. 2 1
      packageA/course/detail.vue
  2. 1 1
      packageA/resourceLibrary/detail.vue
  3. 16 0
      utils/tool.js

+ 2 - 1
packageA/course/detail.vue

@@ -111,11 +111,12 @@ export default {
                 this.files = res.data.attinfos.filter(v => {
                     if (v.usetype == "file") switch (res.data.filetype) {
                         case '视频':
-                            v.showUrl = this.getSpecifiedImage(v, 'hls')
+                            v.showUrl = this.getVideoUrl(v)
                             break;
                     }
                     return v.usetype == "file"
                 });
+                console.log(this.files)
                 this.detail = res.data;
 
                 // 处理PPT预览图片

+ 1 - 1
packageA/resourceLibrary/detail.vue

@@ -115,7 +115,7 @@ export default {
                 res.data.attinfos_pic = res.data.attinfos_pic.map(v => {
                     if (res.data.typestr == '视频') {
                         v.cover = this.getSpecifiedImage(v.attinfos[0], "cover")
-                        v.url = this.getSpecifiedImage(v.attinfos[0], "hls")
+                        v.url = this.getVideoUrl(v.attinfos[0])
                     } else {
                         v.cover = this.getSpecifiedImage(v.attinfos[0], "compressed")
                     }

+ 16 - 0
utils/tool.js

@@ -157,6 +157,22 @@ function mount() {
 
         return item.url || "";
     }
+    
+    // 专门处理视频文件的函数:优先取hls,若未取到取原本的url
+    Vue.prototype.getVideoUrl = (item) => {
+        if (!item) return "";
+        
+        // 优先查找hls格式
+        if (item.subfiles && item.subfiles.length > 0) {
+            const hlsFile = item.subfiles.find(v => v.type == 'hls');
+            if (hlsFile && hlsFile.url) {
+                return hlsFile.url;
+            }
+        }
+        
+        // 未找到hls格式,返回原始url
+        return item.url || "";
+    }
     Vue.prototype.formatTime = (date = new Date(), j1 = '-', j2 = ':') => {
         const year = date.getFullYear()
         const month = date.getMonth() + 1