上传视频的方法

<form>
            <view class="cu-bar bg-white flex ">
                <view class="cu-bar bg-white">
                    <view class="action ">
                        面试视频
                    </view>
                </view>
                <view class="grid col-4 grid-square flex-sub  padding-xs  radius">
                    <view class="bg-img" v-show="stu.mssp!=null">
                        <image :src="$config.apiUrl+stu.mssp" mode="aspectFill"></image>
                        <view class="cu-tag bg-red" @tap.stop="DelImg">
                            <text class='cuIcon-close'></text>
                        </view>
                        <view class="cu-tag bg-red" v-if="stu.msspsh == '审核通过'">
                            <text class='cuIcon-close'></text>
                        </view>
                    </view>
                    <view class="solids" @tap="uploadVideo" v-show="stu.mssp ==''||stu.mssp==null">
                        <text class='cuIcon-cameraadd'></text>
                    </view>
                    <button class='cu-btn bg-blue shadow margin' v-show="stu.mssp!=null" @tap="showModal"
                        data-target="mssp">面试视频预览</button>
                </view>
            </view>
        </form>

uploadVideo() {
                var other = this;
                uni.chooseVideo({
                    sourceType: ['album', 'camera'],
                    success: (res) => {
                        var fileName = res.tempFile.name.split('.');
                        var fileSize = res.size;
                        var fileDuration = res.duration;
                        if (fileName[fileName.length - 1].toLowerCase() != 'mp4' && fileName[fileName.length -
                                1].toLowerCase() != 'mov') {
                            // alert(111)
                            // other.$tip.alert(res.duration);
                            other.$tip.alert("上传视频格式必须为mp4或mov尾缀");
                        } else if (fileSize > 120 * 1000 * 1000) {
                            other.$tip.alert("上传视频大小不能超过120M");
                        } else if (fileDuration < 120 && fileDuration != 0) {
                            other.$tip.alert("上传视频大小不能小于2分钟");
                        } else if (fileDuration == 0) {
                            var ua = window.navigator.userAgent
                                .toLowerCase(); // 不加window部分Android机会显示不了提示图,即判断不了是否是微信
                            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                                other.$http
                                    .upload('/common/uploadWeixin', {
                                        name: 'file',
                                        filePath: res.tempFilePath
                                    })
                                    .then(res => {
                                        other.img = res.data.fileName
                                        other.stu.mssp = res.data.fileName
                                        if (res.data.code == 500) {
                                            other.$tip.alert(res.data.msg);
                                        }
                                    })
                            } else {
                                var fileurl = URL.createObjectURL(res.tempFile);
                                var audioElement = new Audio(fileurl);
                                var duration;
                                audioElement.addEventListener("loadedmetadata", function(_event) {
                                    duration = audioElement.duration;
                                    if (duration >= 120) {
                                        other.$http
                                            .upload('/common/upload', {
                                                name: 'file',
                                                filePath: res.tempFilePath
                                            })
                                            .then(res => {
                                                other.img = res.data.fileName
                                                other.stu.mssp = res.data.fileName
                                                if (res.data.code == 500) {
                                                    other.$tip.alert(res.data.msg);
                                                }
                                            })
                                    } else if (duration == 0) {
                                        other.$tip.alert("当前浏览器不支持视频上传,请更换浏览器后重试");
                                    } else {
                                        other.$tip.alert("上传视频大小不能小于2分钟");
                                    }
                                })

                            }
                        } else {
                            other.$http
                                .upload('/common/upload', {
                                    name: 'file',
                                    filePath: res.tempFilePath
                                })
                                .then(result => {
                                    other.img = result.data.fileName
                                    other.stu.mssp = result.data.fileName
                                    var fileurl = URL.createObjectURL(res.tempFile);
                                    var audioElement = new Audio(fileurl);
                                    /* other.$tip.alert("***"+res.size+"***"+res.duration); */
                                    if (result.data.code == 500) {
                                        other.$tip.alert(result.data.msg);
                                    }

                                })
                        }
                    }
                });
            },
            DelImg(e) {
                uni.showModal({
                    content: '确定要删除吗?',
                    success: res => {
                        if (res.confirm) {
                            this.stu.mssp = null;
                        }
                    }
                })
            },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值