簡體   English   中英

使用javascript在html5中單擊圖像時播放視頻?

[英]Play video when an image is clicked in html5 using javascript?

我是JavaScript的初學者。 我想在HTML5中的特定時間播放特定時間的mp4文件。 首先,我要加載縮略圖。 如果單擊它,我想播放特定時間的視頻文件。 這是我的代碼。 但是它不是從6開始。它只是從頭開始。 我做錯了什么?

<!DOCTYPE html>
<html>
<head>
 <script type="text/javascript">
     function PlayVideo(anchor,vid, start_time, end_time, video_file) {
         document.getElementById(anchor).outerHTML = 
                 "<video id='" + vid + "' controls width='320'> <source src='" + video_file + "'              
                 type='video/mp4'/></video>"

        var video = document.getElementById(vid);

        video.play();
        video.currentTime = start_time;

        video.addEventListener('timeupdate', function() {
            if(this.currentTime > end_time) {
                this.pause();
                this.currentTime = start_time;
            }
        });
        document.getElementById(aid).style.display = "none";
    }
    </script>
</head>
<body>
<a id="anchor" onclick="PlayVideo('anchor','003', 5, 9, 'test.mp4');"><img src ="test.jpg" alt="trail" /></a>

</body>
</html>

嘗試

document.getElementById(anchor).outerHTML = "<video id='" + vid + "' controls width='320'> <source src='" + video_file + "'
type='video/mp4'/></video>";

注意

;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM