[英]vanilla javascript preview video file before upload - NO JQUERY
I have been searching for code to preview a video in client side before upload. 我一直在寻找代码以在上传之前在客户端预览视频。 I have seen MANY with Jquery.
我见过很多Jquery。 Personally i find external libraries bulky..... yet they rely on vanilla javascript to function (ironic..).
我个人觉得外部库很庞大.....但是它们依靠香草javascript来起作用(讽刺..)。 Previously, i found a page that describes this functionality.
以前,我找到了描述此功能的页面。 I can no longer find it.... so i am reaching out to the SO community.
我再也找不到了...。因此,我正在与SO社区联系。 NOT asking for an application, or ready made code.
不要求应用程序或现成的代码。 looking for direction to tutorials/blogs that i can read to make this possible.
寻找我可以阅读的教程/博客的指导以实现这一目标。 TY in advance
提前TY
Within change
event handler of <input type="file">
element you can pass the File
object to URL.createObjectURL()
and set the .src
of the <video>
element to the resulting Blob URL
. 在
<input type="file">
元素的change
事件处理程序中,您可以将File
对象传递给URL.createObjectURL()
并将<video>
元素的.src
设置为结果Blob URL
。
document.querySelector("input[type=file]")
.onchange = function(event) {
let file = event.target.files[0];
let blobURL = URL.createObjectURL(file);
document.querySelector("video").src = blobURL;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.