智能客服
你问我答,随时在线为你解决问题
匿名用户<input ref="file" type="file" capture="user" accept="image/*" style="display:none" @change="filechange"> this.$refs.file.click();方式点击拍摄按钮唤起相机功能,但是在鸿蒙系统的手机中失效(点击没有反应)其他设备正常,此H5页面可以通过小程序进入也可以通过短信链接进入,要如何适配鸿蒙系统呢,麻烦各位老师帮忙看看。
蓝瘦的蜕变
通过H5的capture属性,直接拉起相机进行拍照或者录像。只能使用比较简单的拍照或者录像功能。
<input type="file" accept="video/*" capture="user"/>
Yanyan
<!-- videoCapture.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>
<input type="file" accept="image/*" capture="user"/>
</p>
<p>
<input type="file" accept="video/*" capture="user"/>
</p>
</body>
</html>官方有参考文档
https://developer.huawei.com/consumer/cn/doc/architecture-guides/traffic-v1_1-ts_14-0000002376460965
Super牛马
华夏
方案一:通过H5的capture属性,直接拉起相机进行拍照或者录像。只能使用比较简单的拍照或者录像功能。
<!-- videoCapture.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>
<input type="file" accept="image/*" capture="user"/>
</p>
<p>
<input type="file" accept="video/*" capture="user"/>
</p>
</body>
</html>
方案二:Web组件向用户请求手动授权,获取相机权限。
import { webview } from '@kit.ArkWeb';
import { BusinessError } from '@kit.BasicServicesKit';
import { abilityAccessCtrl } from '@kit.AbilityKit';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
uiContext: UIContext = this.getUIContext();
aboutToAppear() {
// 配置Web开启调试模式
webview.WebviewController.setWebDebuggingAccess(true);
let atManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(this.uiContext.getHostContext(),
['ohos.permission.CAMERA', 'ohos.permission.MICROPHONE'])
.then((data) => {
console.info(`data:${data}`);
console.info('data permissions:' + data.permissions);
console.info('data authResults:' + data.authResults);
}).catch((error: BusinessError) => {
console.error(`Failed to request permissions from user. Code is ${error.code}, message is ${error.message}`);
});
}
build() {
Column() {
Web({ src: $rawfile('videoCall.html'), controller: this.controller })
.fileAccess(false)
.geolocationAccess(false)
.onPermissionRequest((event) => {
if (event) {
this.uiContext.showAlertDialog({
title: 'title',
message: 'text',
primaryButton: {
value: 'deny',
action: () => {
event.request.deny();
}
},
secondaryButton: {
value: 'onConfirm',
action: () => {
event.request.grant(event.request.getAccessibleResource());
}
},
cancel: () => {
event.request.deny();
}
});
}
});
};
}
}
<!-- videoCall.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<video id="video" width="500px" height="500px" autoplay="autoplay"></video>
<canvas id="canvas" width="500px" height="500px"></canvas>
<br>
<input type="button" title="HTML5摄像头" value="开启摄像头" onclick="getMedia()"/>
<script>
function getMedia()
{
// 通过facingMode指定使用摄像头,前置为user,后置为environment
let constraints = {
video: {width: 500, height: 500, facingMode: "user"},
audio: true
};
let video = document.getElementById("video");
let promise = navigator.mediaDevices.getUserMedia(constraints);
promise.then(function (MediaStream) {
video.srcObject = MediaStream;
video.play();
});
}
</script>
</body>
</html>
我要提问题
HarmonyOS H5页面出现截断,该如何设置参数,调整缩放比例(API12+)
应用内H5页面查询通知权限失败
H5页面内长文本内容无法自动换行
HarmonyOS NEXT 如何基于javaScriptProxy和@ohos.contact实现在H5页面获取通讯录电话号码的demo
HarmonyOS web组件中打开H5,H5调不起相机权限(API12+)
HarmonyOS 已经申请摄像头权限,但是在web组件里面还是提示没有摄像头权限(API12+)
HarmonyOS H5内拉起相机失败(API12+)
HarmonyOS 扫码功能,相机启动失败,如何解决?(API12+)
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功