我的基于PC的Web应用程序使用HTML5,我想导入mpeg文件在我的浏览器中播放,这些文件已被其他应用程序保存.有没有办法用HTML5播放这些视频文件?
编辑:
应用程序尝试从本地硬盘驱动器而不是从服务器播放mpeg文件.因此,用户可以选择mpeg文件来播放选定的mpeg文件.
HTML:
<input id="t20provideoinput" type="file" multiple accept="video/*"/>
<video id="t20provideo" controls controls>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
(function localFileVideoPlayerInit(win) {
var URL = win.URL || win.webkitURL;
var sources = [];
var j = 1;
var videoNode = document.querySelector('video');
var videoNode1 = document.querySelector('object');
var groupElement = document.getElementsByClassName('metric')[0];
console.log('this is group element ' + groupElement);
var playSelectedFile = function playSelectedFileInit(event) {
for(var i=0; i<this.files.length; i++){
var file = this.files[i];
var type = file.type;
var fileURL = URL.createObjectURL(file);
sources.push(fileURL);
}
groupElement.addEventListener('click', function(){
videoNode.src = sources[0];
}); …Run Code Online (Sandbox Code Playgroud)