<template>
<view>
<view class="uni-padding-wrap">
<view v-if="videoPath !== ''">
<video
id="myVideo"
:src="videoPath"
@error="videoErrorCallback"
enable-danmu
danmu-btn
controls
></video>
</view>
<button type="primary" @click="saveVideo">录制视频并保存到本地</button>
</view>
<view>
tempFilePath:{{tempFilePath}}
</view>
<view>
tempFile:{{tempFile}}
</view>
<view>
size:{{size}}
</view>
<view>
name:{{name}}
</view>
</view>
</template>
<script>
export default {
data() {
return {
videoPath: '',
tempFilePath: '',
tempFile:'',
size:'',
name:'',
};
},
onLoad() {},
methods: {
videoErrorCallback: function() {
uni.showModal({
content: '视频加载失败',
showCancel: false
});
},
saveVideo() {
let _this = this;
uni.chooseVideo({
count: 1,
sourceType: ['album', 'camera'],
compressed: false,
success: res => {
console.log(res.tempFilePath)
this.tempFilePath = res.tempFilePath;
this.tempFile = res.tempFile;
this.size = res.size;
this.name = res.name;
this.videoPath = res.tempFilePath;
this.getTempFilePath(res.tempFilePath, 'videoTempPath');
},
fail: (err) => {
uni.getSetting({
success: (res) => {
let authStatus = res.authSetting['scope.camera'];
if (!authStatus) {
uni.showModal({
title: '授权失败',
content: 'Hello uni-app需要从您的相机获取视频,请在设置界面打开相关权限',
success: (res) => {
if (res.confirm) {
uni.openSetting()
}
}
})
}
}
})
}
});
},
getTempFilePath(url, types) {
uni.showLoading({
title: '保存中...'
});
// 如果已经下载本地路径,那么直接储存
let obj = {
filePath: url,
success: () => {
uni.showModal({
content: '保存成功',
showCancel: false
});
uni.hideLoading();
},
fail: e => {
uni.hideLoading();
uni.showModal({
content: '保存失败',
showCancel: false
});
}
};
if (types === 'videoTempPath') {
uni.saveVideoToPhotosAlbum(obj);
} else {
uni.saveImageToPhotosAlbum(obj);
}
}
}
};
</script>
<style scoped>
view{
word-wrap:break-word;
word-break:normal;
}
</style>
2***@qq.com
- 发布:2022-08-13 16:57
- 更新:2022-08-13 16:57
- 阅读:609
0 个回复