Open Bug 1805729 Opened 3 years ago Updated 3 years ago

Mediarecorder onstop event is not fired when mic permission is denied and recording mimetype and codec is video/webm;codecs="vp8,opus"

Categories

(Core :: Audio/Video: Recording, defect)

Firefox 107
defect

Tracking

()

People

(Reporter: abhaytank64, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Firefox/107.0

Steps to reproduce:

Code snippet - https://codepen.io/abhay_tank/pen/NWzQWWY

  1. Request microphone permission using navigator.mediaDevices.getUserMedia({video: false, audio: true})
  2. Request display video stream using navigator.mediaDevices.getDisplayMedia({video: true audio: true})
  3. Add all tracks from both sources to new MediaStream object.
  4. Feed new MediaStream object generated in step 3 to MediaRecorder with mimeType video/webm;codecs="vp8,opus"
  5. Attach onstop, ondataavailable listeners.
  6. Bind a button to start and stop mediarecorder.
  7. Start mediarecorder.
  8. Stop mediarecorder after few seconds.

Actual results:

MediaRecorder state switches to inactive but onstop event/callback is not fired. This happens only when audio codec "opus" is passed in mimeType and microphone permission is denied. This defect is not observed in chrome.

Expected results:

Onstop event/callback should've been fired.

The Bugbug bot thinks this bug should belong to the 'Core::Audio/Video: Recording' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Audio/Video: Recording
Product: Firefox → Core

Temporary fix or workaround is to remove codec info, which negates the raised bug OR compute codec and mimetype before creating MediaRecorder object i.e. check if there are audiotracks in stream which will be fed to MediaRecorder, if there is audiotrack, add opus codec in mimetype, else pass only video codec.

Ex.

const getMimeType = (stream) => {
	const hasAudioTrack = Boolean(stream.getAudioTracks().length);
	if (hasAudioTrack) {
		return 'video/webm;codecs="vp8,opus"';
	}
	return "video/webm;codecs=vp8";
};

The severity field is not set for this bug.
:karlt, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(karlt)

Nice testcase, thanks!

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(karlt)

Also, start event is fired when stream stops...

document.body.onclick = (async (e) => {
	const mimeType = e.ctrlKey ? "video/webm;codecs=vp8" : "video/webm;codecs=vp8,opus";
	console.log(mimeType, MediaRecorder.isTypeSupported(mimeType));
	const ms = await navigator.mediaDevices.getDisplayMedia({  });
	console.log(ms);
	const mr = new MediaRecorder(ms, { mimeType });
	console.log(mr);
	mr.onstart = () => console.log('onstart');
	mr.onstop = () => console.log('onstop');
	console.log(mr.state);
	console.log('start');
	mr.start();
	console.log(mr.state);
	await new Promise((resolve) => setTimeout(resolve, 1000));
	console.log('onstart should be called by now');
	await new Promise((resolve) => setTimeout(resolve, 1000));
	console.log('stop');
	mr.stop();
	console.log(mr.state);
});
You need to log in before you can comment on or make changes to this bug.