2017-03-23 3 views
0

:) HTML5ビデオを3回だけループさせようとしています。私は基本的に私がしたいことを行うであろうthis codeスニペットを見つけました。奇妙なことは、私はそれを働かせることができないということです。私はここでデモを実行する場合は、それは動作します。それをコピーして空のhtml文書に貼り付けると、それはしません。何かアドバイス?HTML5ビデオループの数を制限する

ありがとうございました!

+1

私はループ= "3"は –

答えて

0

これをコピーして貼り付けます。これはうまくいくはずです。

<div>Iteration: <span id="iteration"></span></div> 

<video width="320" height="240" id="myVideo" controls> 
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" /> 
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" /> 
    Your browser does not support the video tag. 
</video> 

<script> 
    var iterations = 1; 

    document.getElementById('iteration').innerText = iterations; 

    myVideo.addEventListener('ended', function() {  

     if (iterations < 2) { 
      this.currentTime = 0; 
      this.play(); 
      iterations ++;   
      document.getElementById('iteration').innerText = iterations; 
     } 

    }, false); 
</script> 
0

ボディセクションの最後にJSスクリプトを追加しますか? 本文セクションの最後に(ドキュメントがロードされたときに)スクリプトを追加する必要があります。

+0

いいえと思う。ヘッダーにこれがソースです。 http://pastebin.com/75YHpiZY –

+0

ボディセクションの最後に「」と書いてあります。[pastebin snippet](http://pastebin.com/TVfsyA9n)。確かに – szymon

+0

!ありがとう! –

関連する問題