最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - play video from data in File object - Stack Overflow

matteradmin6PV0评论

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.

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.

Share Improve this question asked Mar 21, 2012 at 10:14 NathanNathan 11.2k4 gold badges40 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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./c04ac1f0-cd88-4587-9905-741b90c62684"

Post a comment

comment list (0)

  1. No comments so far