gpt4 book ai didi

javascript - 手动关闭 getDisplayMedia 的 native 屏幕选择器

转载 作者:行者123 更新时间:2023-11-30 19:07:23 37 4
gpt4 key购买 nike

我可以在不选择要共享的应用程序的情况下关闭 getDisplayMedia({video:true}) 的 native 屏幕选择器吗?据我所知,如果正在共享的轨道停止,它会在 track.stop() 上自动关闭。但是,在某些情况下,我需要在不按取消或选择要共享的应用程序的情况下关闭 native 屏幕选择器。

Screen Picker Img

最佳答案

刷新页面:

window.location = window.location.href;

这将在所有浏览器中消除这个粘性提示。

在 Chrome 中,提示是模态的,但是这个 demo using a timeout对我有用:

const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

button.onclick = async () => {
const stream = await Promise.race([
navigator.mediaDevices.getDisplayMedia({video: true}),
wait(5000)
]);
if (!stream) {
window.location = window.location.href;
}
video.srcObject = stream;

当然,这有可能会在用户使用选择器时撕掉它。

关于javascript - 手动关闭 getDisplayMedia 的 native 屏幕选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58853992/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com