0

onended関数を HTML ビデオで動作させるのに問題があります。そうでなくてonendedもいいんですけど、基本的には動画が終わったら一連のことが起きてほしいです。

コードは次のとおりです。

<script language="JavaScript" type="text/javascript">
window.onload = playVideo;
function playVideo() 
{
    var video = document.getElementById("video");
    var message = document.getElementById("videoinfo");
    var button = document.getElementById("playpause");
    button.onclick = function()
    {
        if (video.paused)
        {
            video.play();
            button.innerHTML = "Pause";
            message.value = "The video is playing, click the Pause button to pause the video.";
        }
        else
        {
            video.pause();
            button.inerHTML = "Play";
            message.value = "The video is paused, click the Play button to play the video.";
        }
        video.onended = function(e)
        {
            button.innerHTML = "Play";
            message.value = "The video has ended, click Play to restart the video."
        }    
    }
}
</script>

<button type="button" id="playpause" onclick="playVideo()">Play</button> 
<br> 
<video id="video" width="320" height="240">
    <source src="Video/movie.mp4" type="video/mp4">
    <source src="Video/movie.ogg" type="video/ogg">
    Your browser does not support HTML5 video.
</video>
<br />
<textarea id="videoinfo" cols="90">
Click the Play button to start the video.
</textarea>

助けてくれてありがとう

編集: 評判が 10 以下の場合、自分の回答を 8 時間投稿することはできないため、編集する必要があります。

これを機能させるために 2 日間試みた後、ここに質問を投稿して、解決できるようにします。10分も経たないうちに、なんとか機能させることができました。

onEndedタグで関数を使用し、<video>それを という JavaScript 関数にリンクしましたvideoEnded()

下記参照:

<script language="JavaScript" type="text/javascript">
function playVideo() 
{
    var video = document.getElementById("video");
    var message = document.getElementById("videoinfo");
    var button = document.getElementById("playpause");
    button.onclick = function()
    {
        if (video.paused)
        {
        video.play();
        button.innerHTML = "Pause";
        message.value = "The video is playing, click the Pause button to pause the video.";
        }
        else
        {
            video.pause();
            button.inerHTML = "Play";
            message.value = "The video is paused, click the Play button to play the video.";
        }
    }
}
function videoEnded()
{
    var message = document.getElementById("videoinfo");
    var button = document.getElementById("playpause");
    button.innerHTML = "Play";
    message.value = "The video has ended, click Play to restart the video.";
}
</script>

これが他の誰かを助けることを願っています。答えを探して何日も探しましたが、何もうまくいきません。

ありがとう

4

1 に答える 1

0
if(Video.ended)

 // Code when video ends.

編集:他の説明をせずに申し訳ありませんが、代わりに .addEventListener メソッドを使用してみましたか? どのブラウザで開発/デバッグしますか?

于 2013-06-04T01:19:04.530 に答える