使用Mediarecorder在打字稿中记录HLS音频流
我有一个HLS音频供稿集作为默认音频播放器元素的来源。我希望能够记录传入流以供以后使用。我尝试使用此 mediarecorder 以捕获来自音频播放器的流我被告知媒体记录器的来源不是“ Mediastream”类型的墙壁。
用于在音频元素代码中播放的流
initStream() {
// get the audio player
let audioEl = this.audioPlayer.nativeElement;
// create the HLS object
this.hls = new Hls();
// stream source URL
var source = "https://as-hls-uk-live.akamaized.net/pool_904/live/uk/bbc_radio_one/bbc_radio_one.isml/bbc_radio_one-audio%3d128000.norewind.m3u8"
// assign the source to the HLS object
this.hls.loadSource(source);
//attach the HLS to the audio player
this.hls.attachMedia(audioEl);
console.log(`Created audioPlayer${this.playerId}`);
}
以初始初始化流录制的流播放的
initRecording(){
this.recorder = null;
this.recordedChunks = [];
try {
this.recorder = new MediaRecorder(this.hls, {mimeType: "audio/ogg"});
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
return;
}
this.recorder.ondataavailable = (event) => {
console.log(' Recorded chunk of size ' + event.data.size + "B");
this.recordedChunks.push(event.data);
};
this.recorder.start();
}
代码,而我获得的错误是异常创建Mediarecorder:TypeError:typeError:无法构造'Mediarecorder':parameter 1不是类型'MediaStream' 。
我还尝试将音频播放器源用作媒体记录器的流,但是在这种情况下,我会发现一个错误,说媒体记录器无法启动录音机,因为源中没有曲目。
initRecording(){
let audioEl = this.audioPlayer.nativeElement;
var audioStream = audioEl.src;
this.recorder = null;
this.recordedChunks = [];
try {
this.recorder = new MediaRecorder(audioStream, {mimeType: "audio/ogg"});
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
return;
}
this.recorder.ondataavailable = (event) => {
console.log(' Recorded chunk of size ' + event.data.size + "B");
this.recordedChunks.push(event.data);
};
this.recorder.start();
}
I have a HLS audio feed set as the source for the default audio player element. I want to be able to record the incoming stream for later use. I have tried using this MediaRecorder to capture the stream from the audio player source but am coming up against a wall where I am told that the source for the media recorder is not of type 'MediaStream'.
Code for initialising the stream to be played in the audio element
initStream() {
// get the audio player
let audioEl = this.audioPlayer.nativeElement;
// create the HLS object
this.hls = new Hls();
// stream source URL
var source = "https://as-hls-uk-live.akamaized.net/pool_904/live/uk/bbc_radio_one/bbc_radio_one.isml/bbc_radio_one-audio%3d128000.norewind.m3u8"
// assign the source to the HLS object
this.hls.loadSource(source);
//attach the HLS to the audio player
this.hls.attachMedia(audioEl);
console.log(`Created audioPlayer${this.playerId}`);
}
Code for initialising the stream recording
initRecording(){
this.recorder = null;
this.recordedChunks = [];
try {
this.recorder = new MediaRecorder(this.hls, {mimeType: "audio/ogg"});
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
return;
}
this.recorder.ondataavailable = (event) => {
console.log(' Recorded chunk of size ' + event.data.size + "B");
this.recordedChunks.push(event.data);
};
this.recorder.start();
}
And the error i get is Exception while creating MediaRecorder: TypeError: Failed to construct 'MediaRecorder': parameter 1 is not of type 'MediaStream'.
I am assuming this is becuase I am passing a HLS object into the media recorder, is there an attribute within that object that i could use instead?
I have also tried to use the audio player source as the stream into the media recorder, but in that case, I get an error saying that the media recorder could not start the recorder as there are no tracks listed in the source.
initRecording(){
let audioEl = this.audioPlayer.nativeElement;
var audioStream = audioEl.src;
this.recorder = null;
this.recordedChunks = [];
try {
this.recorder = new MediaRecorder(audioStream, {mimeType: "audio/ogg"});
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
return;
}
this.recorder.ondataavailable = (event) => {
console.log(' Recorded chunk of size ' + event.data.size + "B");
this.recordedChunks.push(event.data);
};
this.recorder.start();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确实,您需要传递“ MediaStream”类型。
您可以使用
Indeed you need to pass in a 'Mediastream' type.
You can create one using the captureStream method from your audio html media element then pass it to your MediaRecorder