在JavaScript什么是视频相当于"新的音频()" [英] In javascript what is the video equivalent of "new Audio( )"

查看:119
本文介绍了在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.)

这篇关于在JavaScript什么是视频相当于"新的音频()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆