Bug 232981 - MediaRecorder API onstop callback doesn't get called
Summary: MediaRecorder API onstop callback doesn't get called
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: iPhone / iPad iOS 15
: P2 Normal
Assignee: Nobody
URL:
Keywords: HTML5, InRadar
Depends on:
Blocks:
 
Reported: 2021-11-10 20:06 PST by Raja
Modified: 2022-02-12 19:33 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raja 2021-11-10 20:06:28 PST
Hi,

I'm using MediaRecorder for screen recording of canvas , along with audio.

simplified code to implement screen recorder
/* code starts here */
//intialise stream
const canvas = document.querySelector('.main-canvas');
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });

for (let track of canvas.captureStream().getTracks()) {
    stream.addTrack(track);
}
recorder = new MediaRecorder(stream);
chunks = [];
recorder.ondataavailable = ({ data }) => {
    if (data) chunks.push(data);
};


recorder.start();

recorder.onstop = () => {
   const videoBlob =  new Blob(chunks, {
      type: 'video/mp4'
    });
   chunks = []
   //stop mic access after use
   try{
        for (let track of stream.getTracks()) {
            track?.stop();
        }
    }catch(e){}
    return videoBlob;
}

/* code ends here */
so when i call `recorder.stop()` , the `recorder.onstop` method is not getting called sometimes randomly.

And also in case when recorder.onstop is not called , recorder.ondataavailable is not called even a single time,So it returns empty Blob output.

This only occurs in iOS 15 device's , it occurs randomly 40% of the times.

Is there any workaround for this, or what is cause of this issue?

Thanks in advance
Comment 1 youenn fablet 2021-11-17 01:45:54 PST
Hi Raja, do you have any potential repro steps, even if not working 100% of the time?
Do you know if this is iOS specific or also happening in MacOS?

If you can reproduce the issue, can you send me a sysdiagnose (youenn@apple.com) with the information of when the bug did happen?
Comment 2 Radar WebKit Bug Importer 2021-11-17 20:07:37 PST
<rdar://problem/85532501>
Comment 3 Raja 2021-11-17 22:15:46 PST
Hi youenn,

this iOS specific issue(only in iOS 15), this not happening in macOs or other iOS version. I've checked in all device's.

I'll send you playground link to test in few minutes
Comment 4 Geoffrey Garen 2021-12-07 10:05:23 PST
Raja, can you provide that test case?
Comment 5 Raja 2021-12-07 11:32:02 PST
Hi Geoffrey,

Sorry for the delay 
I didn't add code snippet because this issue didn't reproduce in my ipad, after i updated it iOS 15.2, I'll check once again and verify it

For your reference, i adding code file earlier in which I faced issue.

code link- 
https://stackblitz.com/edit/web-platform-gklpub?file=index.html

hosted link - 
https://media-recorder-test.netlify.app/

you can check this in iOS 15.0 or 15.1
ISSUE - onStopEvent function is not called after recording is stopped



Thanks for instant response, & being helpful
Comment 6 youenn fablet 2021-12-15 02:18:52 PST
@raja, can you confirm whether you cannot reproduce anymore in iOS 15.2?
If so, can we mark it as configuration changed?
Comment 7 Brent Fulgham 2022-02-12 19:33:42 PST
This should now be fixed in STP 139, iOS 15.4 Beta, and macOS 12.3 Beta.