在JavaScript什么是视频相当于"新的音频()"
问题描述:
在Javascript中可以访问HTML-5音频对象是这样的:
In Javascript you can access the HTML-5 audio object like this:
var audio = new Audio('nameOfFile.mp3');
但对于视频元素等价语法似乎并没有工作(我在Chrome)。
But the equivalent syntax for the video element doesn't seem to work (I'm on Chrome).
var video = new Video('nameOfFile.ogg');
我很好奇,如果有是的等效对象,我可以通过这个简单的新语法访问视频标签。
I'm curious if there is an equivalent object for the video tag that I can access via this simple new syntax.
答
没有一个,但你可以围绕创建一个很长的路要走:
There isn't one yet, but you can create one the long way around:
var video = document.createElement("video");
video.setAttribute("src", "nameOfFile.ogg");
请注意,视频格式的支持仍然是pretty支离破碎。有否格式,这将在所有的浏览器。 (H264来最接近的,并且它没有Firefox的支持下)。
Note that video format support is still pretty fragmented. There are no formats which will work on all browsers. (H264 comes the closest, and it's not yet supported under Firefox.)