[英]No audio in WebRTC over WebView in Android app
I developed a simple Android app that wrap a WebView to connect to apprtc.appspot.com. 我开发了一个简单的Android应用程序,它包装WebView以连接到apprtc.appspot.com。 The WebRTC session is establish successfully, video streams are shown in both the app and the peer (a Chrome browser on a Mac,) the audio can be heard on the app, but the Mac does not receive any audio.
WebRTC会话成功建立,视频流显示在应用程序和对等设备(Mac上的Chrome浏览器)中,可以在应用程序上听到音频,但Mac不会收到任何音频。 chrome://webrtc-internals on the Mac's Chrome browser shows no error.
Chrome:// Mac上的Chrome浏览器上的webrtc-internals显示没有错误。 WebRTCing from Chrome in the Android device to the Chrome in the Mac works fine with audio.
从Android设备中的Chrome到Mac中的Chrome的WebRTC可以很好地处理音频。 I also wrote a test activity in the app to use MediaRecorder and MediaPlayer that successfully captured and played back audio.
我还在应用程序中编写了一个测试活动,以使用成功捕获和播放音频的MediaRecorder和MediaPlayer。
My permission set up looks like 我的权限设置看起来像
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.audio.low_latency" />
<uses-feature android:name="android.hardware.audio.pro" />
<uses-feature android:name="android.hardware.microphone" android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.front" android:required="true" />
The app codes look like 应用代码看起来像
int permission;
permission = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
if (permission != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.RECORD_AUDIO)) {
// Show an expanation to the user *asynchronously* -- don't block
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO},
MY_PERMISSIONS_REQUEST_AUDIO);
}
}
// ... similar camera permission request ...
WebView webView = (WebView) findViewById(R.id.web_view);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(PermissionRequest request) {
request.grant(request.getResources());
}
});
webView.loadUrl("https://appr.tc/r/my-room");
What goes wrong? 出了什么问题?
在<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
添加<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
为我解决了问题。
加:
settings.setMediaPlaybackRequiresUserGesture(false);
For this problem you have to do these levels : 对于这个问题,你必须做这些级别:
1)define a String : 1)定义一个字符串:
private static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36";
2) 2)
myWebView.getSettings().setUserAgentString(DESKTOP_USER_AGENT);
3) 3)
myWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.