vue--Element-UI上传视频音频获取时

1.封装获取时间方法。

        getTimes(file) {
            var content = file;
            //获取录音时长
            var url = URL.createObjectURL(content);
            //经测试,发现audio也可获取视频的时长
            var audioElement = new Audio(url);
            audioElement.addEventListener("loadedmetadata", (_event) => {
               //保存获取时间长度
                this.dataFile.videoTime = parseInt(audioElement.duration)
            });
        },

2.再upload上传之前拿到上传的file文件,调用方法。

        //上传之前的操作
        // file.type.includes 文件类型判断
        beforeAvatarUpload(file) {
            if (file.type.includes('image')) {
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isLt2M) {
                    this.$message.error('上传图片大小不能超过 2MB!');
                    this.isok = false
                } else {
                    this.isok = true
                    this.updataimg.fileKey = this.utypeTexe
                }

            }
            if (file.type.includes('video')) {
                this.getTimes(file)
                const isLt2M = file.size / 1024 / 1024 < 500;
                if (!isLt2M) {
                    this.$message.error('上传视频大小不能超过 500MB!');
                    this.isok = false
                } else {
                    this.isok = true
                    this.updataimg.fileKey = this.utypeTexe
                }
                
            }

            if (file.type.includes('audio')) {
                this.getTimes(file)
                const isLt2M = file.size / 1024 / 1024 < 500;
                if (!isLt2M) {
                    this.$message.error('上传音频大小不能超过 500MB!');
                    this.isok = false
                } else {
                    this.isok = true
                    this.updataimg.fileKey = this.utypeTexe
                }
                
            }
        },

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Element UI不提供专门用于音频播放的组件。然而,你可以使用Element UI的基本组件和Vue.js提供的原生API来实现一个简单的音频播放器。首先,你可以使用`<el-dialog>`组件来创建一个弹出对话框,用于播放音频。然后,你可以使用Vue.js的`<audio>`标签和相关事件来控制音频的播放、暂停、停止等功能。最后,你可以使用Element UI的其他组件来创建播放列表和控制按钮等界面元素。 以下是一个简单的实现步骤: 1. 在你的页面中引入Element UIVue.js的依赖。 2. 创建一个包含音频播放器的弹出对话框,并在对话框中添加一个`<audio>`标签和相关的控制按钮(例如播放、暂停、停止)。 3. 在点击播放列表中的视频标题,弹出对话框,并将对应的音频文件设置为`<audio>`标签的`src`属性。 4. 使用Vue.js的事件监听机制,监听页面中控制按钮的点击事件,并通过对`<audio>`标签的相关API进行操作,实现音频的播放、暂停、停止等功能。 请注意,以上步骤只是一个简单的示例,你可以根据实际需求进行修改和扩展。同,如果需要更复杂的音频播放功能,建议使用第三方音频播放器库,如阿里云播放器Aliplayer,可以根据中提供的步骤引入并使用该播放器组件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [element-audio:元素用户界面](https://download.csdn.net/download/weixin_42138139/18554298)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Element-UI实现对话框内播放视频](https://blog.csdn.net/qq_41865229/article/details/119448207)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值