gpt4 book ai didi

javascript - HTML 电影播放器​​在最新的 Safari 上无法运行

转载 作者:行者123 更新时间:2023-11-28 04:54:06 33 4
gpt4 key购买 nike

这周我正在面试一家机构,我的面试官对他全新的 mac 书非常满意。当我的小电影播放器​​在最新版本的 Safari 上完全失败时,这有点尴尬。帮忙?

我在搜索在线教程和该网站上的一些线程后将其拼凑在一起。不确定我从哪里得到代码。它位于 kristian.co.nz

将来我想显示接下来将要播放的视频的预览图像,任何有关如何执行此操作的建议将不胜感激。

感谢您的帮助。

<html>
<head>
<script type="text/javascript">
var videoSources = ["http://kristian.co.nz/video/Showreel2016_H264_website4.webm", "http://kristian.co.nz/video/Craftsmanintro_web.webm", "http://kristian.co.nz/video/GTA 03 shark.m4v", "http://kristian.co.nz/video/dj_intro.webm", "http://kristian.co.nz/video/Sketch.webm", "http://kristian.co.nz/video/Monkeybizz.webm"]
var currentIndex = 0;

// listener function changes src
function myNewSrc() {
var myVideo = document.getElementsByTagName('video')[0];
myVideo.src = videoSources[currentIndex];
myVideo.load();
}

// add a listener function to the ended event
function myAddListener(){
var myVideo = document.getElementsByTagName('video')[0];
currentIndex = (currentIndex+1) % videoSources.length;
myVideo.src = videoSources[currentIndex];
myVideo.addEventListener('ended', myNewSrc, false);
}
</script>
</head>

<body onload="myNewSrc()">

<div id="section-title" >
<video preload="auto" onended="myAddListener()" controls width="100%" title="" src="" poster="images/introMovie_poster.gif">
</video>

</div>
</body>
</html>

最佳答案

一种方法是创建另一个数组来保存视频海报/缩略图。然后添加一个监听器,以便在视频播放时显示下一个剪辑的缩略图/海报。在下面的示例中,我仅使用一个单独的 div 标签,其中显示“下一个剪辑”,并在调用监听器函数时显示下一个剪辑的缩略图,并访问海报/缩略图数组中的下一个缩略图并将其加载到 img src 标签中。

<html>
<head>
<script type="text/javascript">
var videoSources = ["http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", "http://kristian.co.nz/video/GTA%2003%20shark.m4v", "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"];

var currentIndex = 0;

var videoThumbnails = ["https://placehold.it/150x100.jpg","https://placehold.it/150x200.jpg","https://placehold.it/150x300.jpg","https://placehold.it/150x400.jpg","https://placehold.it/150x480.jpg"];

// listener function changes src
function myNewSrc() {
var myVideo = document.getElementsByTagName('video')[0];
myVideo.src = videoSources[currentIndex];
myVideo.load();
}

function myNewThumb() {
var nextThumb = document.getElementsByTagName('img')[0];
nextThumbIndex = (currentIndex+1) % videoThumbnails.length;
nextThumb.src = videoThumbnails[nextThumbIndex];
nextThumb.load();

}

// add a listener function to the ended event
function myAddListener(){
var myVideo = document.getElementsByTagName('video')[0];
currentIndex = (currentIndex+1) % videoSources.length;
myVideo.src = videoSources[currentIndex];
myVideo.addEventListener('ended', myNewSrc, false);
myVideo.addEventListener('progress',myNewThumb,false);
}
</script>
</head>

<body onload="myNewSrc(),myNewThumb()">

<div id="section-title" >
<video preload="auto" onended="myAddListener()" controls width="480" height="360" title="" src="" poster="https://placehold.it/350x150">
</video>


</div>
<div id="movie_image">
<p>Next clip playing:</p>
<img src="" alt="video image">
</div>
</body>
</html>

关于javascript - HTML 电影播放器​​在最新的 Safari 上无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42684579/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com