js获取音频时长

我用的element 的上传功能

<el-upload ref="iconUrl" :action="iconUrlAction" name="upload" :on-success="thumbnailSuccess">
              <div class="dis_flex">
                <div>
                  <div class="uploadBut">
                    <el-button size="small" type="primary">点击上传</el-button>
                  </div>
                </div>
              </div>
            </el-upload>
  // 文件上传成功时的钩子
  thumbnailSuccess(res: any, file: any) { 
    if (res) { 
      let audio: any = document.createElement("audio"); //生成一个audio元素
      audio.src = res.path; //音乐的路径
      audio.addEventListener("canplay", function () { 
        console.log(parseInt(audio.duration));
      });
    }
  }
    原文作者:南桥几许
    原文地址: https://blog.csdn.net/z17864151193/article/details/109774486
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞