HTML5 video player: dynamically loading videos

China☆狼群 提交于 2020-01-01 04:21:05

问题


So, using a HTML 5 compliant video player, (like Video JS) how would one go about loading a video dynamically, without having to reload the entire page? Imagine, a list of links (something like a playlist), and each link points to a video. When clicking the link, I want to load the selected video into player.

Currently, I'm using an Iframe that holds the video player, so basically a I pass a variable on to the Iframe, and reload it. I don't think this is ideal, for a few reasons; it doesn't allow the video to go full screen, the Back button moves the Iframe back not just the main page, plus, it's an Iframe. I'd rather avoid this.

Ideas? Thanks!


回答1:


Came up with a simple solution. Here's the script; throw this in the head:

function vidSwap(vidURL) {
var myVideo = document.getElementsByTagName('video')[0];
myVideo.src = vidURL;
myVideo.load();
myVideo.play();
}

And then the HREF will call the function:

<a href="#" onClick="javascript:vidSwap('myMovie.m4v'); return false;">Link</a>


来源:https://stackoverflow.com/questions/3602525/html5-video-player-dynamically-loading-videos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!