Search code examples
javascriptmacosgoogle-chromewebrtcgetusermedia

getUserMedia use audio only will be closed by itself in few seconds on mac chrome


The same code bellow, you can run it in chrome console on both windows OS and Mac OS.

navigator.mediaDevices.getUserMedia({audio: true})

On my Mac, it will be closed in a few seconds.

On my Windows, it works fine.

In my project, there are no any code changed, it works fine in the past few months... but these days, it's broken on mac chrome...

See sample code here Sample code

Steps:

  1. Click on show button, you can get undefined

  2. Click on start button.

  3. After Media started, click show button, you can get a MediaStream object with active: true. And you can see the red circle on chrome tab.

  4. Wait a few seconds(maybe 10s), you can see the red circle on chrome tab will missing, then click the show button, you can get a MediaStream object with active: false.

BTW, this issue is on mac chrome, windows chrome is correct.

==============chrome://media-internals/====================

After use getUserMedia({audio: true}), it shows an item in input controllers, then I open it as follow, but after a few seconds. this item disappeared.

channel_layout: STEREO
channels: 2
component_id: 5
component_type: 0
device_id: default
device_type: pcm_low_latency
effects: NO_EFFECTS
frames_per_buffer: 441
owner_id: 6976
render_process_id: 7664
sample_rate: 44100
status: started
web_contents_title: javascript - getUserMedia use audio only will be closed by itself in few seconds on mac chrome - Stack Overflow

Solution

  • Not sure, maybe the OS and chrome issue.

    I upgrade mac os from 10.12.5 -> 10.12.6, and chrome from 61 -> 62, issue solved.