[Vue] Realize the screen recording function and save it locally

One, Vue

We still use the Vue.js file from the previous article

Here Vue implements the camera function

2. Create a directory

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkDlsI_nmq7njKo,size_8,color_FFFFFF,t_70,g_se,x_16

3. Realization 

1.  index.html

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkDlsI_nmq7njKo,size_20,color_FFFFFF,t_70,g_se,x_16

 

Code:

 



<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="vue.js"></script>
    </head>
    <body>
        <div id="vueapp">
            <div>
                <button @click="btnRecordClicked" :disabled="recording">录制</button>
                <button @click="btnPauseClicked" :disabled="paused||!recording">暂停</button>
                <button @click="btnResumeClicked" :disabled="!paused||!recording">继续</button>
                <button @click="btnStopClicked" :disabled="!recording">停止</button>
                <button :disabled="!currentWebmData" @click="btnPlayClicked">播放</button>
            </div>
            <video controls ref="player"></video>
        </div>
        <script src="app.js"></script>
    </body>
</html>


2. app.js

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkDlsI_nmq7njKo,size_20,color_FFFFFF,t_70,g_se,x_16

code


 new Vue({     el:"#vueapp",     data:{         currentWebmData:0,         recording:false,         paused:false     },     mounted() {         this._initApp();     },     methods:{         async _initApp(){             // this._stream=await navigator.mediaDevices.getUserMedia({audio:true,video:false});             this._stream=await navigator.mediaDevices.getDisplayMedia();             this._recorder=new MediaRecorder(this._stream,{mimeType:"video/webm;codecs=h264"});             this._recorder.ondataavailable=this.recorder_dataAvailableHandler.bind(this);         },









    







        recorder_dataAvailableHandler(e){             console.log(e);             this.currentWebmData=e.data;         },         btnRecordClicked(){             this.recording=true;             this.paused=false;             this._recorder.start();         },         btnPauseClicked(){             this.paused=true;             this._recorder.pause();         },         btnResumeClicked(){             this.paused=false;             this._recorder.resume();         },         btnStopClicked(){             this.recording=false;             this._recorder.stop();



















        },
        btnPlayClicked(){             this.$refs.player.src=URL.createObjectURL(this.currentWebmData);}     } });



Fourth, the effect

1. Select the range to recordwatermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkDlsI_nmq7njKo,size_20,color_FFFFFF,t_70,g_se,x_16

 2. You can click to start recording

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkDlsI_nmq7njKo,size_20,color_FFFFFF,t_70,g_se,x_16

 

Guess you like

Origin blog.csdn.net/m0_56233309/article/details/124133560