当使用以下函数将视频动态加载到画布上时,我正在尝试找到一种方法来提供正确的视频格式(我的视频以 h264 和 webm 编码):
function loadVideo(video_path){
var ctx = document.getElementById('c').getContext('2d');
var vid = document.getElementById('v');
vid.src = video_path;
vid.load();
// play the video once it has loaded
vid.addEventListener('canplay', function(e){
vid.style.display = "block";
vid.play();
}, false);
// hide the video container once the video has finished playing
vid.addEventListener('ended', function(e){
vid.style.display = "none";
}, false);
}
这是body
标签内的简单html:
<video id="v" type="video/webm" width="960" height="500"></video>
<canvas id="c"></canvas>
我可以沿着用户代理嗅探路线为我提供正确的video_path
字符串,但有没有更优雅的方法?