1

ビデオ (HTML5) に必要なコントロールの実例があります。私が理解しようとしているのは、一度だけ再生可能にする方法であり、それ以上ではありません. 私が今持っているコードは、ビデオが終了するたびに再生ボタンを戻します。2回目ではなく、1回目のプレイ後に表示させたいです。ありがとう。

HTML:

<video id="erbVid" width="320" height="240" autoplay="autoplay">
<source src="Question_2_Video.mp4" type="video/mp4"></source>
</video>

jQuery:

$(document).ready(function() {
    $("#replayButton").hide();    
    $("video").bind("ended", function() {
        $("#replayButton").show();
    });
    $("#replayButton").click(function() {
        $("video")[0].play();
        $("#replayButton").hide();
    });    
});
4

1 に答える 1

0

変数を追加して、ビデオが既に再生されているかどうかを確認し、その変数に基づいて何かを行うことができます。

$(document).ready(function() {
    // Create your boolean variable showing the video has not yet been replayed
    var replayed = false;

    $("#replayButton").hide();

    $("video").bind("ended", function() {
        // Check if the video has been replayed
        if(!replayed){
            // If not, do something and set replayed to true
            $("#replayButton").show();
            replayed = true;
        }
    });
    $("#replayButton").click(function() {
        $("video")[0].play();
        $("#replayButton").hide();
    });    
});

ビデオが再生されると、再生ボタンは表示されなくなります。次のようにして、多数のリプレイを許可することもできます。

var replayed = 0;
var replayed_max = 5;

$("video").bind("ended", function() {
    // Check if the video has been replayed the max number of times
    if(replayed < replayed_max){
        // If not, do something and add 1 to replayed
        $("#replayButton").show();
        replayed++;
    }
});
于 2012-12-05T18:02:16.987 に答える