<u-button shape="circle" @click="selectVideo">选择视频</u-button>
//选择视频
selectVideo: function () {
var _this = this;
uni.chooseMedia({
count: 1,
sourceType: ['camera', 'album'],
maxDuration:30,
mediaType:['image', 'video'],
sizeType:['original', 'compressed'],
success: function (res) {
console.log("video:",res);
// console.log("sp",res.tempFiles[0].thumbTempFilePath);
// console.log("video",res.tempFiles[0].temporarySrc);
if(res.tempFiles[0].duration > 301){
uni.showToast({
title:'视频超过5分钟',
icon:'error',
duraiont:1500
})
}
else {
_this.video.temporarySrc = res.tempFiles[0].tempFilePath;
// _this.video.thumbTempFilePath = res.tempFiles[0].thumbTempFilePath
//启动上传等待中...
uni.showLoading({
title:'正在上传...'
})
uni.uploadFile({
url: _this.$c.domain + 'common/upload',
filePath: res.tempFiles[0].tempFilePath,
name: 'File',
header: {
},
success: res=> {
console.log("视频 res:",res);
var data = JSON.parse(res.data);
if(res.code == '500'){
uni.showToast({
title:'视频过大上传失败',
icon:'none' ,
duration: 5000
})
return;
}
_this.video.src = data.url;
uni.hideLoading()
},
fail: res=> {
uni.hideLoading()
uni.showModal({
title: '错误提示',
content: '上传视频失败',
showCancel: false,
success: res=> {}
})
}
});
uni.uploadFile({
url: _this.$c.domain + 'common/upload',
filePath: res.tempFiles[0].thumbTempFilePath,
// thumbTempFilePath:res.tempFiles[0].thumbTempFilePath,
name: 'File',
header: {
},
success: res=> {
console.log("缩略图 res:",res);
var data = JSON.parse(res.data);
if(res.code == '500'){
uni.showToast({
title:'视频过大上传失败',
icon:'none' ,
duration: 5000
})
return;
}
_this.video.thumbTempFilePath = data.url;
uni.hideLoading()
},
fail: res=> {
uni.hideLoading()
uni.showModal({
title: '错误提示',
content: '上传视频失败',
showCancel: false,
success: res=> {}
})
}
});
}
}
});
},
1 个回复
DCloud_UNI_Anne
单独测试一下微信小程序(不使用 uni-app 时),是否存在此问题,如果仍然存在,反馈到微信小程序社区