- 发布:2023-12-06 10:38
- 更新:2023-12-06 10:38
- 阅读:175
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
HBuilderX类型: 正式
HBuilderX版本号: 3.98
手机系统: 全部
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
<template>
<view>
<button type="primary" size="mini" @tap="addVideo(true)">上传视频</button>
<button type="default" size="mini" @tap="addVideo(false)">保存相册</button>
</view>
</template>
<script>
export default {
data() {
return {
videoHint: '',
}
},
methods: {
addVideo(isUploadVideo) {
let self = this;
uni.chooseVideo({
compressed: false,
sourceType: ['camera', ], //开启视频相机
maxDuration: 60 * 5, //时长 5分钟
mediaType: ['video'], //类型为视频
success: (res) => {
if (res.duration < 300) {
uni.showToast({
title: '视频录制时间不足 5 分钟!',
icon: 'none',
});
return;
}
let videPath = plus.io.convertLocalFileSystemURL(res.tempFilePath)
self.videoCompress(videPath, isUploadVideo);
},
fail: (err) => { //提示
this.videoHint = '视频录制失败';
console.log('err: ', err);
uni.showToast({
title: '视频录制失败!',
icon: 'none',
});
}
})
},
// 视频压缩
videoCompress(tempFilePath, isUploadVideo) {
this.videoHint = '晨会视频压缩中...'
var that = this;
let time = `${uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd-hh:MM:ss')}.mp4`
console.log('tempFilePath: ', tempFilePath);
uni.getVideoInfo({
src: tempFilePath,
success: (res) => {
console.log('getVideoInfoSucc: ', res);
},
fail: (res) => {
console.log('getVideoInfoFail: ', res);
}
})
let params = {
src: tempFilePath, //路径
quality: 'medium', //'low':低,'medium':中,'high':高
}
// 第一种方式
plus.zip.compressVideo(params, (success) => {
console.log('success: ', success);
let filePath = plus.io.convertLocalFileSystemURL(success.tempFilePath)
if (isUploadVideo) {
this.videoHint = '晨会视频压缩完成'
// that.getAliyunOssPolicy(filePath)
} else {
that.saveMeetingLog(5);
}
}, (error) => {
this.videoHint = '晨会视频压缩失败'
uni.showToast({
title: '视频压缩失败',
icon: 'none'
})
})
//第二种方式
uni.compressVideo({
src: tempFilePath,
quality: 'medium', //'low':低,'medium':中,'high':高
success: function(res) {
console.log('压缩后大小---', res.size / 1024 / 1024 + 'M');
let filePath = plus.io.convertLocalFileSystemURL(res.tempFilePath)
if (isUploadVideo) {
that.videoHint = '晨会视频压缩完成';
// that.getAliyunOssPolicy(filePath)
} else {
uni.saveImageToPhotosAlbum({
filePath: filePath,
success(path) {
console.log('saveImageToPhotosAlbum: ', path);
that.baseInfo.imgPaths = path.path;
that.videoHint = '保存相册成功,请用PC端上传视频';
uni.showToast({
title: '保存相册成功',
icon: 'none'
});
},
fail() {
that.videoHint = '保存相册失败';
uni.showToast({
title: '保存相册失败',
icon: 'none'
});
}
})
}
},
fail: function(err) {
console.log(err)
uni.showToast({
title: '视频压缩失败',
icon: 'none'
})
}
});
}
},
}
</script>
<style>
</style>
<template>
<view>
<button type="primary" size="mini" @tap="addVideo(true)">上传视频</button>
<button type="default" size="mini" @tap="addVideo(false)">保存相册</button>
</view>
</template>
<script>
export default {
data() {
return {
videoHint: '',
}
},
methods: {
addVideo(isUploadVideo) {
let self = this;
uni.chooseVideo({
compressed: false,
sourceType: ['camera', ], //开启视频相机
maxDuration: 60 * 5, //时长 5分钟
mediaType: ['video'], //类型为视频
success: (res) => {
if (res.duration < 300) {
uni.showToast({
title: '视频录制时间不足 5 分钟!',
icon: 'none',
});
return;
}
let videPath = plus.io.convertLocalFileSystemURL(res.tempFilePath)
self.videoCompress(videPath, isUploadVideo);
},
fail: (err) => { //提示
this.videoHint = '视频录制失败';
console.log('err: ', err);
uni.showToast({
title: '视频录制失败!',
icon: 'none',
});
}
})
},
// 视频压缩
videoCompress(tempFilePath, isUploadVideo) {
this.videoHint = '晨会视频压缩中...'
var that = this;
let time = `${uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd-hh:MM:ss')}.mp4`
console.log('tempFilePath: ', tempFilePath);
uni.getVideoInfo({
src: tempFilePath,
success: (res) => {
console.log('getVideoInfoSucc: ', res);
},
fail: (res) => {
console.log('getVideoInfoFail: ', res);
}
})
let params = {
src: tempFilePath, //路径
quality: 'medium', //'low':低,'medium':中,'high':高
}
// 第一种方式
plus.zip.compressVideo(params, (success) => {
console.log('success: ', success);
let filePath = plus.io.convertLocalFileSystemURL(success.tempFilePath)
if (isUploadVideo) {
this.videoHint = '晨会视频压缩完成'
// that.getAliyunOssPolicy(filePath)
} else {
that.saveMeetingLog(5);
}
}, (error) => {
this.videoHint = '晨会视频压缩失败'
uni.showToast({
title: '视频压缩失败',
icon: 'none'
})
})
//第二种方式
uni.compressVideo({
src: tempFilePath,
quality: 'medium', //'low':低,'medium':中,'high':高
success: function(res) {
console.log('压缩后大小---', res.size / 1024 / 1024 + 'M');
let filePath = plus.io.convertLocalFileSystemURL(res.tempFilePath)
if (isUploadVideo) {
that.videoHint = '晨会视频压缩完成';
// that.getAliyunOssPolicy(filePath)
} else {
uni.saveImageToPhotosAlbum({
filePath: filePath,
success(path) {
console.log('saveImageToPhotosAlbum: ', path);
that.baseInfo.imgPaths = path.path;
that.videoHint = '保存相册成功,请用PC端上传视频';
uni.showToast({
title: '保存相册成功',
icon: 'none'
});
},
fail() {
that.videoHint = '保存相册失败';
uni.showToast({
title: '保存相册失败',
icon: 'none'
});
}
})
}
},
fail: function(err) {
console.log(err)
uni.showToast({
title: '视频压缩失败',
icon: 'none'
})
}
});
}
},
}
</script>
<style>
</style>
操作步骤:
当天偶尔复现,第二天 第一次必现
当天偶尔复现,第二天 第一次必现
预期结果:
尽快修复,压缩成功,不再压缩失败
尽快修复,压缩成功,不再压缩失败
实际结果:
压缩成功,不再压缩失败
压缩成功,不再压缩失败
bug描述:
1、Android
honor,NTH-AN00,Android 12; huawei,CET-AL00,Android 12;huawei,ANG-AN00,Android 12;xiaomi,23116PN5BC,Android 14
({"code":-99,"message":"Surface frame wait timed out"})
huawei,RTE-AL00,Android 12
({"code":-99,"message":"Error 0xffffffe0"})
huawei,HMA-AL00,Android 10
({"code":-99,"message":"null"})
2、iOS
{"code":-100,"message":"[Zip:-11800]这项操作无法完成,"}
0 个回复