MediaStream in Safari fails to release resources correctly
P粉106715703
P粉106715703 2023-08-30 17:23:15
0
1
451
<p>I am using the AudioWorkletNode method to record and all browsers seem to be recording fine. </p> <p>When I record, the recording icon appears on the tab and disappears when the recording ends. </p> <p> However, in Safari, a small speaker icon (usually indicating that the tab is emitting sound) will appear on the tab instead of the microphone icon. </p> <p>So I think I may not have closed something. </p> <p>After the recording is completed I will do the following:</p> <pre class="brush:php;toolbar:false;">//stream is a MediaStream type if(stream) stream.getTracks().forEach(track => track.stop()); stream = null</pre> <p>The stream is created via: </p> <pre class="brush:php;toolbar:false;">stream = await navigator.mediaDevices.getUserMedia({ audio: options });</pre> <p>Is there anything else needed to release all resources? </p>
P粉106715703
P粉106715703

reply all(1)
P粉536909186

To turn everything off, the following method seems to work. I just found this through trial and error because I couldn't figure out how to get Safari to tell me what it still holds:

// stream : MediaStream
// sourceNode : MediaStreamAudioSourceNode
// recorderNode : AudioWorkletNode

const tracks = stream.getTracks();
tracks.forEach((track) => {
  track.stop();
  stream.removeTrack(track)
});
stream = null

sourceNode.disconnect();
sourceNode = undefined

recorderNode.disconnect();
recorderNode = undefined
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!