l***@163.com
l***@163.com
  • 发布:2025-03-31 16:35
  • 更新:2025-04-07 11:30
  • 阅读:36

video 不显示摄像头预览

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 15.3.2 (24D81)

HBuilderX类型: 正式

HBuilderX版本号: 4.57

浏览器平台: Chrome

浏览器版本: 134.0.6998.166

项目创建方式: HBuilderX

App下载地址或H5⽹址: static-mp-eeaaf131-f61b-4010-ad07-f75cd812a4f1.next.bspapp.com

示例代码:

<template>
<view class="rootView">

<video ref="video" autoplay playsinline muted id="video" style="width: 100px; height: 100px;"></video>  
<button v-on:click="startRecording">开启摄像头</button>  
<button v-on:click="stopRecording">关闭摄像头</button>  

</view>
</template>
<script>
export default {
name: 'indexPage',
data: function() {
return {
mediaRecorder: null,
videoStream: '',
videoElement: null,
chunks: [],
}
},
onLoad() {
},
mounted() {

},  
methods: {  
    async startRecording() {  
        try {  
            const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });  
            if(this.$refs.video) {  
                this.$refs.video.srcObject = stream;  
            }  
        } catch (error) {  
            console.error('Error accessing media devices.', error);  
        }  
    },  
    stopRecording() {  
    },  
    stopCamera() {  
    },  
    test() {  
        uni.chooseVideo({  
            sourceType: ['camera', 'album'],  
            success: function (res) {  
                self.src = res.tempFilePath;  
            }  
        });  
    }  
}  

}
</script>
<style>

</style>

操作步骤:

直接点击打开摄像头按钮

预期结果:

显示预览画面

实际结果:

未显示画面

bug描述:

web 端使用 video 显示摄像头预览时,未出现预览画面

2025-03-31 16:35 负责人:无 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

权限申请了吗,普通的 h5 页面展示是否正常?是在浏览器打开还是微信打开?

要回复问题请先登录注册