前端写了个vue 版本的语音通话,采用的腾讯的TRTC SDK,本地浏览器调试正常,但是集成到webview 中后,通话接听后挂断,于是连Android studio查看了下 问题,一直报 “CheckMediaAccessPermission: Not supported.” 集成方式是自己手动写的webview 加载
原始代码如下:
LinearLayout view=findViewById(R.id.test);
mAgentWeb = AgentWeb.with(this)
.setAgentWebParent((LinearLayout) view, new LinearLayout.LayoutParams(-1, -1))
.useDefaultIndicator()
.createAgentWeb()
.ready()
.go("file:///android_asset/index.html#/");
mAgentWeb.getJsInterfaceHolder().addJavaObject("psycloudapp",new PsyCloudVoice(this));
IAgentWebSettings agentWebSettings = mAgentWeb.getAgentWebSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
agentWebSettings.getWebSettings().setSafeBrowsingEnabled(false);
}
agentWebSettings.getWebSettings().setMediaPlaybackRequiresUserGesture(false);
agentWebSettings.getWebSettings().setDomStorageEnabled(true);
这个错误,开始猜测是没有申请到语音的权限。
于是查找问题,按照这个文章修改了下配置 https://stackoverflow.com/questions/38917751/webrtc-error-inside-chromium-webview-checkmediaaccesspermission-not-supported
LinearLayout view=findViewById(R.id.test);
mAgentWeb = AgentWeb.with(this)
.setAgentWebParent((LinearLayout) view, new LinearLayout.LayoutParams(-1, -1))
.useDefaultIndicator()
.setWebChromeClient(mWebChromeClient)
.createAgentWeb()
.ready()
.go("file:///android_asset/index.html#/");
mAgentWeb.getJsInterfaceHolder().addJavaObject("psycloudapp",new PsyCloudVoice(this));
IAgentWebSettings agentWebSettings = mAgentWeb.getAgentWebSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
agentWebSettings.getWebSettings().setSafeBrowsingEnabled(false);
}
agentWebSettings.getWebSettings().setMediaPlaybackRequiresUserGesture(false);
agentWebSettings.getWebSettings().setDomStorageEnabled(true);
private WebChromeClient mWebChromeClient=new WebChromeClient(){
@Override
public void onPermissionRequest(PermissionRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String[] resources = request.getResources();
request.grant(resources);
}
}
};
结果还是不行,于是去翻了下腾讯的官方文档 https://github.com/LiteAVSDK/TRTC_Web/tree/main/base-react-next ,发现这样一段话
由于 H.264 版权限制,华为系统的 Chrome 浏览器和以 Chrome WebView 为内核的浏览器均不支持 TRTC 的 Web 版 SDK 的正常运行。
于是在webview 中打开如下网址检测了支持度
https://web.sdk.qcloud.com/trtc/webrtc/demo/detect/index.html
发现不支持 H264
于是乎只能更换 wbeview 内核,由于是腾讯的服务,所以更换为腾讯的X5 内核,具体更换流程,腾讯官方给的很清楚,参考 https://x5.tencent.com/docs/access.html