简体   繁体   中英

play video from data in File object

Is it possible to play video by somehow passing data from a File object into a <video> tag?

I know you can base64 encode things to put include the data in the DOM, but I understand there are size limits on this, so can anyone think of another way, or a workaround for this?

For now it's just a bit of an experiment, so lets not worry too much about video file formats... just assume that the format works with the browser you're using.

URL.createObjectURL will create urls that link to the files, otherwise you will just crash your browser.

var URL = window.URL || window.webkitURL;
var src = URL.createObjectURL( file );

videoElem.src = src;

The urls will use blob scheme, example:

"blob:http%3A%2F%2Fstackoverflow.com/c04ac1f0-cd88-4587-9905-741b90c62684"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM