美文网首页
input获取视频后预览

input获取视频后预览

作者: ThemisHoo | 来源:发表于2019-05-30 17:48 被阅读0次

支持MP4,不支持mov格式视频

/*
* videofile 传入的视频文件
**/
creatFileSrc = (videofile) => {
        const reader = new FileReader();
        reader.onload = (evt) => {
            const myVideo = document.querySelector("#myVideo");
            myVideo.src = evt.target.result;
        };
        reader.readAsDataURL(videofile);

        myVideo.play().then(() => {
            console.log('视频播放成功')
        }).catch((error) => {
            console.error('此视频不支持预览', error)
        })
}

<video id="myVideo" autoPlay width="300"/>

可以预览MP4,MOV格式的封面,不能正常播放视频

// 直接将 videofile 视频文件给 src
<video width="320" height="240" controls="controls">
     <source src={videoFile} type="video/mov"/>
     <source src={videoFile} type="video/mp4"/>
     your browser does not support the video tag.
</video>

相关文章

网友评论

      本文标题:input获取视频后预览

      本文链接:https://www.haomeiwen.com/subject/xpcmtctx.html