亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

重新加載后繼續使用頁面上的 getDisplayMedia 進行錄制

重新加載后繼續使用頁面上的 getDisplayMedia 進行錄制

四季花海 2023-11-02 22:54:37
我正在使用 錄制網頁上的屏幕navigator.mediaDevices.getDisplayMedia。但是當我重新加載頁面時,它就停止了。我想自動繼續錄制。是否可以?也許我可以以某種方式使用本地存儲,重新加載的頁面會嘗試再次錄制,但隨后再次出現選擇要錄制的屏幕的提示,但我想像以前一樣選擇相同的屏幕來自動錄制,這樣每次頁面重新加載后,用戶都不會受到打擾。有什么辦法嗎,也許服務人員可以解決這個問題?謝謝。
查看完整描述

1 回答

?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

MediaStream 與其領域的負責文檔相關聯。當此文檔的權限策略更改或文檔死亡(卸載)時,MediaStream 捕獲的軌道將結束。

對于您的情況,唯一的方法是從其他文檔(彈出窗口/選項卡)開始錄制,您的用戶必須始終保持打開狀態。


在要記錄的頁面中:

const button = document.querySelector( "button" );

const video = document.querySelector( "video" );

// We use a broadcast channel to let the popup window know we did reload

// When the popup receives the message

// it will set our video's src to its stream

const broadcast = new BroadcastChannel( "persistent-mediastream" );

broadcast.postMessage( "ping" );

// wait a bit for the popup has the time to set our video's src

setTimeout( () => {

? if( !video.srcObject ) { // there is no popup yet

? ? button.onclick = (evt) => {

? ? ? const popup = open( "stream-master.html" );

? ? ? clean();

? ? };

? }

? else {

? ? clean();

? }

}, 100);

function clean() {

? button.remove();

? document.body.insertAdjacentHTML("afterBegin", "<h4>You can reload this page and the stream will survive</h4>")

}

并在彈出的頁面中


let stream;

const broadcast = new BroadcastChannel( "persistent-mediastream" );

// when opener reloads

broadcast.onmessage = setOpenersVideoSource;


const button = document.querySelector( "button" );

// we need to handle an user-gesture to request the MediaStream

button.onclick = async (evt) => {

? stream = await navigator.mediaDevices.getDisplayMedia( { video: true } );

? setOpenersVideoSource();

? button.remove();

? document.body.insertAdjacentHTML("afterBegin", "<h4>Go back to the previous tab</h4>");

};

function setOpenersVideoSource() {

? if( opener ) {

? ? opener.document.querySelector( "video" ).srcObject = stream;

? }

}



查看完整回答
反對 回復 2023-11-02
  • 1 回答
  • 0 關注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號