我正在测试Tab Capture API以记录包含文本到语音flash对象的网页的音频。录制网页时,播放音频会消失,但录制的文件中听起来不错。
我使用以下MediaStream约束来录制视频和音频。
var MediaStreamConstraint = {
audio: true,
video: true,
videoConstraints: {
mandatory: {
chromeMediaSource: 'tab',
minWidth: 640,
maxWidth: 640,
minHeight: 420,
maxHeight: 420
}
}
};
我是否在流约束中遗漏了某些内容,或者还有其他解决问题的方法?
答案 0 :(得分:2)
正如其他人所说,在回调中播放来自捕获的MediaStream的音频:
chrome.tabCapture.capture(MediaStreamConstraint, gotStream);
function gotStream(stream) {
window.audio = document.createElement("audio");
window.audio.src = window.URL.createObjectURL(stream);
window.audio.play()
}
答案 1 :(得分:1)
请记住在清单文件中授予权限
"permissions": [
"tabCapture",
"activeTab",
...
],
background.js应该是这样的:
var recorder = new MRecordRTC();
function handleCapture(stream) {
recorder.addStream(stream);
recorder.mediaType = { video: true, audio: true };
recorder.startRecording();
}
var MediaStreamConstraint = {
audio: true,
video: true,
videoConstraints: {
mandatory: {
chromeMediaSource: 'tab',
minWidth: 640,
maxWidth: 640,
minHeight: 420,
maxHeight: 420
}
}
};
function captureCurrentTab() {
chrome.tabCapture.capture(MediaStreamConstraint, handleCapture);
}
function stopCapturing() {
// stops the recording and save audio and video
}
如果不属于这种情况,请附上更多相关代码,因为您附带的代码对我来说很好。
答案 2 :(得分:1)
在后台脚本的handleCapture功能中,尝试此操作以继续播放:
var audio = new Audio(window.URL.createObjectURL(stream));
audio.play();

答案 3 :(得分:-1)
只添加下一行
window.audio = document.createElement("audio");
window.audio.src = window.URL.createObjectURL(stream);
window.audio.play()