uniapp上传录制的视频
时间: 2023-08-03 12:05:52 浏览: 167
uniapp 多视频上传原生插件(android)
5星 · 资源好评率100%
在uniapp中上传录制的视频,可以使用uniapp的上传组件和uniapp的录音/录视频组件结合使用。具体步骤如下:
1. 在页面中引入上传组件和录音/录视频组件:
```html
<template>
<view>
<!-- 上传组件 -->
<upload-file :upload-url="uploadUrl" @success="onUploadSuccess"></upload-file>
<!-- 录音/录视频组件 -->
<video-record :show="showVideoRecord" @record-finish="onRecordFinish"></video-record>
</view>
</template>
<script>
import uploadFile from '@/components/upload-file/upload-file.vue'
import videoRecord from '@/components/video-record/video-record.vue'
export default {
components: {
uploadFile,
videoRecord
},
data () {
return {
uploadUrl: '<your-upload-url>',
showVideoRecord: false,
videoSrc: ''
}
},
methods: {
onUploadSuccess (res) {
console.log('上传成功:', res)
// 上传成功后可以将返回的视频地址保存到data中
this.videoSrc = res.data
},
onRecordFinish (res) {
console.log('录制完成:', res)
// 录制完成后可以将返回的视频地址保存到data中,并触发上传操作
this.videoSrc = res.tempFilePath
this.$refs.uploadFile.uploadFile()
}
}
}
</script>
```
2. 在页面中添加触发录音/录视频组件的按钮:
```html
<template>
<view>
<!-- 触发录音/录视频的按钮 -->
<button @tap="showVideoRecord = true">开始录制</button>
</view>
</template>
```
3. 在uniapp的上传组件中调用上传接口上传录制的视频:
```html
<template>
<view>
<!-- 上传组件 -->
<upload-file :upload-url="uploadUrl" @success="onUploadSuccess" ref="uploadFile"></upload-file>
<!-- 录音/录视频组件 -->
<video-record :show="showVideoRecord" @record-finish="onRecordFinish"></video-record>
</view>
</template>
<script>
import uploadFile from '@/components/upload-file/upload-file.vue'
import videoRecord from '@/components/video-record/video-record.vue'
export default {
components: {
uploadFile,
videoRecord
},
data () {
return {
uploadUrl: '<your-upload-url>',
showVideoRecord: false,
videoSrc: ''
}
},
methods: {
onUploadSuccess (res) {
console.log('上传成功:', res)
// 上传成功后可以将返回的视频地址保存到data中
this.videoSrc = res.data
},
onRecordFinish (res) {
console.log('录制完成:', res)
// 录制完成后可以将返回的视频地址保存到data中,并触发上传操作
this.videoSrc = res.tempFilePath
this.$refs.uploadFile.uploadFile()
}
}
}
</script>
```
以上就是在uniapp中上传录制的视频的方法,希望对你有帮助。
阅读全文