【问题标题】:How to stop chrome from capturing a tab?如何阻止chrome捕获标签?
【发布时间】:2015-03-13 12:13:30
【问题描述】:

我正在尝试构建一个类似于 chromecast 的 chrome 扩展。我正在使用chrome.tabCapture 成功启动音频/视频流。如何停止屏幕截图?我想要一个停止按钮,但我不知道该调用什么来停止它。我可以停止 LocalMediaStream,但选项卡仍在捕获,并且不允许我在不关闭选项卡的情况下开始新的捕获。有什么建议或者我可能错过的 api 页面?

【问题讨论】:

  • 来自文档:“在标签页内的页面导航中保持捕获,并在标签页关闭或媒体流被扩展程序关闭时停止。”
  • 请添加您用来“停止LocalMediaStream”的代码
  • Actullay 我也有同样的问题stackoverflow.com/questions/34715357/…,要停止localMediastream,我们必须使用stream.stop() ,但chrome会抛出类似Uncaught TypeError: stream.stop is not a function的错误

标签: javascript google-chrome google-chrome-extension webrtc chromecast


【解决方案1】:

尝试stream.getVideoTracks()[0].stop(); 停止屏幕截图。要记录使用 chrome.tabCapture API 捕获的流,您可以使用 RecordRTC.js

var video_constraints = {
    mandatory: {
        chromeMediaSource: 'tab'
    }
};
var constraints = {
    audio: false,
    video: true,
    videoConstraints: video_constraints
};

chrome.tabCapture.capture(constraints, function(stream) {
    console.log(stream)
    var options = {
        type: 'video',
        mimeType : 'video/webm',
        // minimum time between pushing frames to Whammy (in milliseconds)
        frameInterval: 20,
        video: {
            width: 1280,
            height: 720
         },
         canvas: {
            width: 1280,
            height: 720
         }
     };
     var recordRTC = new RecordRTC(stream, options);
     recordRTC.startRecording();

    setTimeout(function(){
        recordRTC.stopRecording(function(videoURL) {
            stream.getVideoTracks()[0].stop();
            recordRTC.save();
         });
    },10*1000);
});

希望上面的代码 sn-p 对你有帮助:)

编辑 1:更正了 RecordRTC 初始化。

【讨论】:

  • 我更好地格式化了你的代码(请学习如何在 SO 上使用多行代码),但我仍然没有得到你的 mediaRecorder 评论,你能解释一下吗?
  • 对不起,它的 RecordRTC.js 必须用于记录到您的流中,通过 chrome.tabCapture API 获得
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-16
  • 2023-04-01
  • 1970-01-01
  • 2013-11-12
  • 2020-11-06
  • 1970-01-01
相关资源
最近更新 更多