5

In Javascript you can access the HTML-5 audio object like this:

var audio = new Audio('nameOfFile.mp3');

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.

4

2 回答 2

9

目前还没有,但您可以创建一个很长的路要走:

var video = document.createElement("video");
video.setAttribute("src", "nameOfFile.ogg");
于 2013-03-08T04:09:58.563 回答
4

以防万一你需要,我有一个,非常相似的new Audio()东西......

function Video(src, append) {
  var v = document.createElement("video");
  if (src != "") {
    v.src = src;
  }
  if (append == true) {
    document.body.appendChild(v);
  }
  return v;
}

然后你可以像这样使用它:

var video = new Video("YOUR_VIDEO_URL", true);
// do whatever you want...
video.height = 280;
video.width = 500;
video.controls = "controls";
video.play();
于 2018-03-29T14:00:38.700 回答