如何用JS添加多个视频源?
编辑:我想我没有正确解释自己。
我需要(通过 JavaScript)为我的视频设置多个视频源。
例如设置:
<source type="video/mp4" src="video.mp4"></source>
<source type="video/ogg" src="video.ogg"></source>
有什么办法可以做到这一点吗?另外,如果我只有当前网络浏览器不支持的视频,它会回退到 Flash 吗?
我使用 mediaelementjs (和 jquery)(简而言之,我需要的是单击图像,并且神奇地必须加载浏览器支持的视频(另一个视频))。
谢谢!
EDIT: I think i haven't explained myself correctly.
I need to set (via javascript) more than one video source to my video.
For example set:
<source type="video/mp4" src="video.mp4"></source>
<source type="video/ogg" src="video.ogg"></source>
is there any way to do this? also if i only have a video that the currently web browser doesn't support will it fallback to flash?
Im using mediaelementjs (and jquery) (in a few words, what i need is to click an image and magically the browser supported video (another video) must load).
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以设置多个源,这样浏览器将仅加载支持的源,如果不支持 HTML5 视频,它将加载嵌入标签(flash),
这里是一个示例:
- -- 已编辑 ---
所以,您想动态添加更多源标签。就像 onclick 函数一样。您有一些选择:
src
属性;src
属性;在任何这些情况下,您都需要在更改或添加源后运行视频元素的
load
和play
函数;PS:请记住,只会播放一种源,即浏览器可以读取的源。因此,您不能添加大量视频(例如不同的视频,而不是不同的扩展名)并期望创建一个播放列表;
有关于此的更多问题:
Yeah man, you can set more than one source so, the browser will load just the supported source , and in case that it doesn't support HTML5 video, it will load the embed tag (flash)
Here an example:
--- edited ---
So, you wanna to add more source tags dynamically. Like an onclick function. You have some options:
src
attribute in video element;src
attribute of each source element;In any of these cases, you will need to run the
load
andplay
functions of video element after changes or add sources;PS: remember that only one source will be played, the one that the browser can read. So you can't add a lot of videos (like different videos, instead differents extensions) and expect that a playlist will be created;
More questions about it: