5

I developed a simple Android app that wrap a WebView to connect to 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. chrome://webrtc-internals on the Mac's Chrome browser shows no error. WebRTCing from Chrome in the Android device to the Chrome in the Mac works fine with audio. I also wrote a test activity in the app to use MediaRecorder and MediaPlayer that successfully captured and played back audio.

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?

3 Answers 3

10

Adding <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> in the permission solved the problem for me.

9

Add:

settings.setMediaPlaybackRequiresUserGesture(false);
2
  • 1
    This saved my day
    – Dewsworld
    Jun 12, 2020 at 21:35
  • You are the men!! Nov 25, 2022 at 16:51
1

For this problem you have to do these levels :

1)define a String :

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)

myWebView.getSettings().setUserAgentString(DESKTOP_USER_AGENT);

3)

myWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.