vue 实现录制视频后上传到php后台 借鉴代码

 

demo下载地址https://download.csdn.net/download/qq_39070698/10566294

<body>
    <article style="border:1px solid white;width:400px;height:400px;margin:0 auto;background-color:white;">

        <section class="experiment" style="width:320px; height:240px;border:1px solid green; margin:50px auto;">
            <div id="videos-container" style="width:320px; height:240px;">
            </div>
        </section>
        <section class="experiment" style="text-align:center;border:none; margin-top:20px;">
            <button id="openCamera">打开摄像头</button>
            <button id="start-recording" disabled>开始录制</button>
            <button id="save-recording" disabled>保存</button>
            <!--<a href="javascript:void(0)" onclick="send()">发送</a>-->
        </section>
      </article>


</script>

该demo可以通过录像生成MP4格式的文件流   方便操作下面是我在vue中使用上传视频流时的代码

function saver(){
    var file = new File([recorderFile], 'msr-' + (new Date).toISOString().replace(/:|\./g, '-') + '.mp4', {
        type: 'video/mp4'
    });
    console.log(file)
    var data = new FormData();
    data.append("userfile", file);
	var req = new XMLHttpRequest();
    req.open("POST", "url");
    req.send(data);
    req.onreadystatechange = function() {
    			var res = req.responseText;
		    	if(req.readyState == XMLHttpRequest.DONE && req.status == 200) {
		    		var jsonObj =  JSON.parse(res)
			       // console.log(jsonObj)
			       // console.log(jsonObj.status)
			       // console.log(jsonObj.data)
			        that.videolist = [{url:jsonObj.data,introduce:''}]
			        console.log(that.videolist)
			    }
	}
}

该demo代码较多  不能一一贴出来,demo下载后直接可以在浏览器运行,详细情况可以根据业务需求自己倒腾 

后台是PHP顺便也给贴出来希望对大家有帮助

 public function upload($name="video",$path='video'){
        $file   = $this->request->file('userfile');
        $result = $file->move('.' . DS .'upload'. DS . $path . DS);
        if ($result) {
            $avatarSaveName = str_replace('//', '/', str_replace('\\', '/', $result->getSaveName()));
            $savepath = "./upload/".$path.'/'.$avatarSaveName;
            $this->ajaxReturn(array('status'=>'0','data'=>$savepath));
        }else{
            $this->ajaxReturn(array('status'=>'1','data'=>$file->getError()));
        }
        
    }

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值