如何收听“停止分享”点击Chrome DesktopCapture API [英] How to listen for "Stop sharing" click in Chrome DesktopCapture API

查看:145
本文介绍了如何收听“停止分享”点击Chrome DesktopCapture API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个Chrome扩展程序,它使用的MediaStream,但MediaStream的结束属性仍然设置为 true



唯一的区别是我可以找到流之间(单击按钮之前和之后)是 videoTracks.readyState 设置为结束。 p>

编辑:
我还想注意用户是否关闭了之前流式传输的窗口。

解决方案

我通过在 videoTrack's onended 属性上分配EventHandler来解决此问题:

  //有人点击编辑停止共享
stream.getVideoTracks()[0] .onended = function(){
// doWhatYouNeedToDo();
};

就我的编辑而言(注意到一个关闭窗口):它也触发事件。 p>

I'm currently writing a chrome extension which uses Chrome's DesktopCapture API. I'm struggling to set a callback when someone clicks on "Stop sharing".

I tried using the onended EventHandler of the MediaStream, but the MediaStream's ended property is still set to true after clicking on the button.

The only difference I could find between the stream (before and after clicking the button) is that the videoTracks.readyState is set to ended.

Edit: I would also like to notice if the user closes the window they were streaming before.

解决方案

I solved this issue by assigning an EventHandler on the videoTrack's onended property:

  // somebody clicked on "Stop sharing"
  stream.getVideoTracks()[0].onended = function () {
    // doWhatYouNeedToDo();
  };

As far as my edit goes (noticing a closing window): it also fires the event.

这篇关于如何收听“停止分享”点击Chrome DesktopCapture API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆