浏览器屏幕共享

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <video autoplay playsinline muted></video>
    <button id="startButton">开始</button>
    <div id="errorMsg" style="color:red;">这里显示错误信息</div>
    <script>
        // let voices=[] //用了存放预设的人物信息
        // speechSynthesis.onvoiceschanged=function(){
        //     voices=speechSynthesis.getVoices().filter(i=>i.lang.includes('zh'))
        //     console.log(voices);
        //     let sayer=new SpeechSynthesisUtterance(`
        //     我叫你好`)
        //     sayer.voice=voices[0]
        //     speechSynthesis.speak(sayer)
        // }
        const startButton=document.getElementById('startButton')
        startButton.addEventListener('click',()=>{
            navigator.mediaDevices.getDisplayMedia({video:true}).then(handleSuccess,handleError)
        })
        function handleSuccess(stream){
            startButton.disabled=true
            const video=document.querySelector('video')
            video.srcObject=stream
            stream.getVideoTracks()[0].addEventListener('ended',()=>{
                errorMsg('The user has ended sharing the screen')
                startButton.disabled=false
            })
        }
        function handleError(error){
            errorMsg(`getDisplayMedia error:${error.name}`,error)
        }
        function errorMsg(msg,error){
            const errorElement=document.querySelector('#errorMsg')
            errorElement.innerHTML+=`<p>${msg}</p>`
            if(typeof error!=='undefined'){
                console.error(error);
            }
        }
    </script>

</body>
</html>
posted @   7c89  阅读(89)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
点击右上角即可分享
微信分享提示