Could not start audio source

Could not start audio source

I have added this piece of code in my project

Then I’m trying to access a video stream using getUserMedia

When I test this in my emulators it works on android versions 5 and up, however when I run it on an actual device I get this error

NotReadableError Could not start source

I have added the cordova-plugin-media-capture plugin to make sure my app will request the appropriate permissions, however I don’t want to use the plugin I’d rather use the getUserMedia API.

So far my researches show that the reason for this error is that some other app is already using the camera but that’s not the case, I even went a step further and restarted the device, then opened my app, making sure there are no other running apps and I still got the error.

Has anyone had this issue?

2 Answers 2

Update — 14/09/2019

SFSafariViewController has gained getUserMedia functionality (. however I need to confirm this, please see below for reports of it working)

However WKWebView does not seem to gain getUserMedia functionality:

iOS 13 and Safari 13 release notes:

Update — 04/11/2018 — Links to working Ionic, Cordova and Native android examples with instructions

Steps to achieve getUserMedia access on Android via the Cordova framework are:

  • Follow Cordova Android install instructions (link)
  • Add Permissions to AndroidManifiest.xml (link)
  • Save WebRTC Adapter.js file to ./www/js/adapter.js and include in ./www/index.html
  • Add cordova plugin add cordova-plugin-android-permissions
  • Add plugin permission code, and the necessary getUserMedia code inside of the ./www/js/index.js file. Make sure you use getUserMedia adapter. Please see this file as an example (link).

Please see the full line by line instructions with a success and error image inside the GitHub project.

Читайте также:  Iphone 5s выключился не включается заряжается

I am not sure how much of this relates to Cordova. However I had this error when I made my own Android getUserMedia test app (link). It is dependant mainly on the native app user permissions, then how the parent app creates the webviews, which version of webrtc is packaged within your app, and how you call getUserMedia.

JavaScript side of the application: Rather than doing browser shim code yourself make sure you use the WebRTC adapter (link). This removes a lot of common problems. You can see an example here (link). I also recommend looking at the WebRTC Samples here (link).

Native side of the application: You will need Mic and Camera user permissions for Video and Audio. This is the main culprit. You need to make sure they have been accepted before the creation of the WebView. Thus all permission checking, popups, etc, need to happen before the creation of the WebView. If permissions are granted after you most likely need to reboot the App, etc.

When you build and deploy your application go to App Settings and manually turn on the permissions if you haven’t been prompted already. Then it should work.

I wasn’t able to get Video/Audio emulation working in the emulator only on the actual device. I also only encountered the NotReadableError on Android utilising a WebChromeView before permissions have been accepted. Lastly The min API version for Android is 21 (Lollipop) for this functionality as the parent application needs to allow run-time permissions via WebView onPermissionRequest (link).

As numerous in-app browsers (Facebook, Pinterest, etc) do not handle onPermissionRequest on Android WebRTC via a website typically doesn’t work. On iOS it is guaranteed (as of April 2018) not to work as Apple have only allowed WebRTC access through the Safari only. Thus Cordova is limited to Android API 21 if it handles the permissions correctly.

Читайте также:  Github как запустить проект

Comments

Copy link Quote reply

spiffytech commented Sep 15, 2018

My app uses WebRTC audio fine in the browser, but when I open the app on my Android phone, I get the console error "DOMException: Could not start audio source".

Here’s how I’m trying to read audio:
const stream = await navigator.mediaDevices.getUserMedia();

I have given my app the Android microphone permission ( ).

This comment has been minimized.

Copy link Quote reply

jcesarmobile commented Sep 20, 2018

Looks like RECORD_AUDIO permission is not enough, you also need

But this will only work on Android 5, on Android 6+ you’ll need to manually request the permissions and the user will have to grant them.

This comment has been minimized.

Copy link Quote reply

jcesarmobile commented Sep 20, 2018

Just saw we can see when the webview permissions are requested, I can use that to request the required native permissions too, will work on a PR.

My audio stopped working recently. There were no particular events that could have prompted this (maybe an automatic OS update).

I’m running Windows 8.1 on a Dell Inspiron.

At first I was getting the following error message on startup (and whenever starting a program that requires audio):

C:Windowssystem32MMDevAPI.DLL is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support.

A system restore to a few days before the sound loss got rid of this error, but did not fix the issue of no sound. No sound icon appears in the taskbar.

Читайте также:  Asus support device что это

Upon checking services.msc, I see that Windows Audio is not running. Two of its dependencies, RPC amd Multimedia Class Scheduler are running with no problem. Windows Audio Endpoint Builder is not running. All services are set to startup automatically.

Attempting to start Windows Audio gives the error message:

Windows could not start the Windows Audio service on Local Computer.

Error 1068: The dependency service or group failed to start.

Attempting to start Windows Audio Endpoint Builder gives the error message:

Windows could not start the Windows Audio Endpoint Builder service on Local Computer.

  • Diagnosing the problem in BIOS: audio plays in this diagnostic, so must be a software problem
  • System restart
  • System restore
  • Starting/restarting the services
  • Checking that Plug and Play and Power services are running (both of which have been reported to affect this)
  • Fixing the problem in: Device Manager >Sound, video and game controllers (listed are Conexant SmartAudio HD and Intel(R) Display Audio)
    • Updating driver software
    • Disabling then re-enabling
    • Uninstalling, then restarting system to automatically install these
    • Updating driver software then manually choosing High Definition Audio Device
    • Running the Windows audio troubleshooter, it gives One or more audio service isn’t running and no options
    • DISM failed. No operation was performed. For more information, review the log file.

      The DISM log file can be found at C:WINDOWSLogsDISMdism.og

      Checking the log file, the error(s) seem to start at around this point (previous lines omitted for brevity):

      Ссылка на основную публикацию
      Adblock detector