是否可以更改 MediaRecorder 的流? [英] Is it possible to change MediaRecorder's stream?
问题描述
getUserMedia(constrains).then(stream => {
var recorder = new MediaRecorder(stream)
})
recorder.start()
recorder.pause()
// get new stream getUserMedia(constrains_new)
// how to update recorder stream here?
recorder.resume()
有可能吗?我尝试创建 MediaStream 并使用 addTrack 和 removeTrack 方法来更改流轨道但没有成功(当我尝试使用更新的流恢复它时,记录器停止)
Is it possible? I've try to create MediaStream and use addTrack and removeTrack methods to change stream tracks but no success (recorder stops when I try to resume it with updated stream)
有什么想法吗?
推荐答案
简短的回答是否定的,这是不可能的.MediaStream 录制规范 明确描述了这种行为:https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start.该算法的要点 15.3 说如果在任何时候,一个轨道被添加到流的轨道集中或从流的轨道集中删除,UA 必须立即停止收集数据......".
The short answer is no, it's not possible. The MediaStream recording spec explicitly describes this behavior: https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start. It's bullet point 15.3 of that algorithm which says "If at any point, a track is added to or removed from stream’s track set, the UA MUST immediately stop gathering data ...".
但如果您只想录制音频,您可以使用 AudioContext 来代理您的流.创建 MediaStreamAudioDestinationNode 并使用它提供的流进行录制.然后,您可以将带有 MediaStreamAudioSourceNodes 和/或 MediaStreamTrackAudioSourceNodes 的流送入音频图中,并以您想要的任何方式混合它们.
But in case you only want to record audio you can probably use an AudioContext to proxy your streams. Create a MediaStreamAudioDestinationNode and use the stream that it provides for recording. Then you can feed your streams with MediaStreamAudioSourceNodes and/or MediaStreamTrackAudioSourceNodes into the audio graph and mix them in any way you desire.
最后但并非最不重要的是,目前计划将您正在寻找的功能添加到规范中.也许你只需要等一会儿.或者可能会更长一些,具体取决于您使用的浏览器.:-)
Last but not least there are currently plans to add the functionality you are looking for to the spec. Maybe you just have to wait a bit. Or maybe a bit longer depending on the browser you are using. :-)
https://github.com/w3c/mediacapture-record/issues/167
https://github.com/w3c/mediacapture-record/pull/186
这篇关于是否可以更改 MediaRecorder 的流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!