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.
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.
Share Improve this question edited Mar 8, 2013 at 3:53 999k 6,5652 gold badges31 silver badges32 bronze badges asked Mar 8, 2013 at 3:52 WilliamWilliam 4,58818 gold badges66 silver badges116 bronze badges 02 Answers
Reset to default 12There isn't one yet, but you can create one the long way around:
var video = document.createElement("video");
video.setAttribute("src", "nameOfFile.ogg");
Just in case you need, I have one, quite similar to the new Audio()
thing...
function Video(src, append) {
var v = document.createElement("video");
if (src != "") {
v.src = src;
}
if (append == true) {
document.body.appendChild(v);
}
return v;
}
You can then use it like this:
var video = new Video("YOUR_VIDEO_URL", true);
// do whatever you want...
video.height = 280;
video.width = 500;
video.controls = "controls";
video.play();