javascript里面需要上传视频,如何做到本地预览视频

javascript里面需要上传视频,如何做到本地预览视频,第1张

<input type="file" accept="video/*" onChange={this.previewVideo} />

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

使用FileReader读取转为Data URL:

previewVideo = (file) => {

    // 建议判断下视频大小及格式,太大的可能会有问题

    const reader = new FileReader()

    reader.onload = (evt) => {

      const myVideo = document.querySelector("#myVideo")

      myVideo.src = evt.target.result

    }

    reader.readAsDataURL(file)

}

<!DOCTYPE HTML>

<html>

<body>

<video src="/i/movie.ogg" controls="controls">

your browser does not support the video tag

</video>

</body>

</html>

http://www.w3school.com.cn/tiy/t.asp?f=html5_video

用HTML5标签,或者直接引用youku tudou上的视频也就是flash需要手机支持。。。。。前者需要浏览器支持。。。。一般说手机上都是google浏览器都是支持HTML5标签的。你可以试试


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11549346.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存