admin管理员组文章数量:1023220
Im trying to add mediaTrack to the mediaStream while MediaRecorder is in state 'recording'
The code for adding a new track is the following:
activeStream.addTrack(newAudioTrack)
After that the event (onstop) was triggered. How can I avoid this?
Im trying to add mediaTrack to the mediaStream while MediaRecorder is in state 'recording'
The code for adding a new track is the following:
activeStream.addTrack(newAudioTrack)
After that the event (onstop) was triggered. How can I avoid this?
Share Improve this question asked Feb 22, 2021 at 14:48 Andrew MedvedevAndrew Medvedev 651 silver badge8 bronze badges 2- Hi Andrew, does the answer over here solve your question as well? stackoverflow./questions/57838283/… – chrisguttandin Commented Feb 22, 2021 at 17:26
- Thank you for your link, but I still have don`t understand how i can replace the track during the recording. Tracks merging with AudioContext it's OK, but before Recording, is not it? – Andrew Medvedev Commented Feb 22, 2021 at 19:05
1 Answer
Reset to default 8You can use an AudioContext
to create a fixed MediaStream
that you can pass to the MediaRecorder
. This allows you to change the input when recording.
const audioContext = new AudioContext();
const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(audioContext);
const mediaRecorder = new MediaRecorder(mediaStreamAudioDestinationNode.stream);
Let's say you have a MediaStream
called initialMediaStream
. You could connect it like that:
const mediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(
audioContext,
{ mediaStream: initialMediaStream }
);
mediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);
You can then start recording the initialMediaStream
.
mediaRecorder.start();
Later on you can replace the initialMediaStream
with anotherMediaStream
.
const anotherMediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(
audioContext,
{ mediaStream: anotherMediaStream }
);
anotherMediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);
mediaStreamAudioSourceNode.disconnect();
You could even use GainNode
s to apply a cross-fade between the two streams if that's what you want.
Im trying to add mediaTrack to the mediaStream while MediaRecorder is in state 'recording'
The code for adding a new track is the following:
activeStream.addTrack(newAudioTrack)
After that the event (onstop) was triggered. How can I avoid this?
Im trying to add mediaTrack to the mediaStream while MediaRecorder is in state 'recording'
The code for adding a new track is the following:
activeStream.addTrack(newAudioTrack)
After that the event (onstop) was triggered. How can I avoid this?
Share Improve this question asked Feb 22, 2021 at 14:48 Andrew MedvedevAndrew Medvedev 651 silver badge8 bronze badges 2- Hi Andrew, does the answer over here solve your question as well? stackoverflow./questions/57838283/… – chrisguttandin Commented Feb 22, 2021 at 17:26
- Thank you for your link, but I still have don`t understand how i can replace the track during the recording. Tracks merging with AudioContext it's OK, but before Recording, is not it? – Andrew Medvedev Commented Feb 22, 2021 at 19:05
1 Answer
Reset to default 8You can use an AudioContext
to create a fixed MediaStream
that you can pass to the MediaRecorder
. This allows you to change the input when recording.
const audioContext = new AudioContext();
const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(audioContext);
const mediaRecorder = new MediaRecorder(mediaStreamAudioDestinationNode.stream);
Let's say you have a MediaStream
called initialMediaStream
. You could connect it like that:
const mediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(
audioContext,
{ mediaStream: initialMediaStream }
);
mediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);
You can then start recording the initialMediaStream
.
mediaRecorder.start();
Later on you can replace the initialMediaStream
with anotherMediaStream
.
const anotherMediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(
audioContext,
{ mediaStream: anotherMediaStream }
);
anotherMediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);
mediaStreamAudioSourceNode.disconnect();
You could even use GainNode
s to apply a cross-fade between the two streams if that's what you want.
本文标签: javascriptAdding an AudioTrack while the MediaRecorder is in state 39recording39Stack Overflow
版权声明:本文标题:javascript - Adding an AudioTrack while the MediaRecorder is in state 'recording' - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745557678a2155972.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论