question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error opening your camera and/or microphone: could not start audio source

See original GitHub issue

I have already taken the permission from the user to access the camera and microphone in webview still my react native app is showing me this error. I don’t know why as I have already checked my website on a mobile browser which is working fine after giving permissions for camera and microphone I am able to do video call through the mobile browser itself but on webview I can’t as it is showing me the error.

Error opening your camera and/or microphone: could not start audio source in webview react native

import React, {useEffect, useState} from 'react';
import {ActivityIndicator, PermissionsAndroid} from 'react-native';
import WebView from 'react-native-webview';

const App = () => {
  const [url, setUrl] = useState('https://be-swasth.com');
  const [userAgent, setUserAgent] = useState(
    'Mozilla/5.0 (Linux; An33qdroid 10; Android SDK built for x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.185 Mobile Safari/537.36',
  );

  cameraPermission = async () => {

    let granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        title: "Camera Permission",
        message:
          "App needs access to your camera " +
          "so others can see you.",
        buttonNeutral: "Ask Me Later",
        buttonNegative: "Cancel",
        buttonPositive: "OK"
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera");
    } else {
      console.log("Camera permission denied");
    }
}

micPermission = async () => {

let granted = await PermissionsAndroid.request(
  PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
  {
    title: "Audio Permission",
    message:
      "App needs access to your audio / microphone",
    buttonNeutral: "Ask Me Later",
    buttonNegative: "Cancel",
    buttonPositive: "OK"
  }
);

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
  console.log("You can use the Microphone");
} else {
  console.log("Microphone permission denied");
}  
}

    useEffect(() => {
      cameraPermission();
      micPermission();
    }, []);
    return (
      <WebView
        userAgent={userAgent} //Set your useragent (Browser) **Very Important
        originWhitelist={['*']}
        allowsInlineMediaPlayback
        bounces={true}
        source={{
          uri: url, //URL of your redirect site
        }}
        startInLoadingState
        scalesPageToFit
        javaScriptEnabled={true}
        renderLoading={() => (
          <ActivityIndicator
            color="blue"
            size="large"
            style={{
              flex: 1,
            }}
          />
        )}
      />
    );
  };
export default App;
AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.beswasth">

    <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
    </application>
</manifest>

Do I need to change something in my code? How can I access my camera and microphone in webview?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
ste7encommented, Apr 7, 2022

Solved by setting these in my AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.VIDEO_CAPTURE" />
    <uses-permission android:name="android.permission.AUDIO_CAPTURE" />

    <uses-feature android:name="android.hardware.camera" android:required="false" />

I’m using these permissions (asked before loading the WebView) to enable a videochat in iframe.

0reactions
github-actions[bot]commented, Jun 8, 2022

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Could not start audio source" in Windows or Webclient - 3CX
I installed the Windows client and worked with USB Headphone. ... a month ago it stopped working with error Could not start audio...
Read more >
"Audio Error: Could Not Start Audio Source" - users
My microphone is no longer being recognized in Jitsi Meetings when launching in CHROME. When starting or joining a meeting i have an...
Read more >
Why is my camera or microphone not working?
Audio problems? Camera not working? Try these steps to resolve the problem! The following video shows you how to do some basic...
Read more >
891190 - After updating to new version, browser declares that ...
Open the browser ... In Chromium, the error showed is Microphone Blocked. ... NotReadableError: Could not start audio source NotReadableError: Could not ......
Read more >
NotReadableError: Could not start source - Stack Overflow
So far my researches show that the reason for this error is that some other app is already using the camera but that's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found