Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML Video - Actions OnEnd not Working
    primarykey
    data
    text
    <p>I am having trouble getting the <code>onended</code> function to work with my HTML video. It doesnt have to be <code>onended</code> but basically I want a series of things to happen when the video has ended. </p> <p>Code is as follows:</p> <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt; 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." } } } &lt;/script&gt; &lt;button type="button" id="playpause" onclick="playVideo()"&gt;Play&lt;/button&gt; &lt;br&gt; &lt;video id="video" width="320" height="240"&gt; &lt;source src="Video/movie.mp4" type="video/mp4"&gt; &lt;source src="Video/movie.ogg" type="video/ogg"&gt; Your browser does not support HTML5 video. &lt;/video&gt; &lt;br /&gt; &lt;textarea id="videoinfo" cols="90"&gt; Click the Play button to start the video. &lt;/textarea&gt; </code></pre> <p>Thanks for the help</p> <p>EDIT: I cannot post my own answer for 8 hours with 10 or less reputation, so I have to edit:</p> <p>After 2 days of trying to get this to work, I post a question on here so I can figure it out. Less than 10 mins later I manage to get it to work.</p> <p>I used an <code>onEnded</code> function in the <code>&lt;video&gt;</code> tag and linked that to a javascript function called <code>videoEnded()</code>.</p> <p>See below:</p> <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt; 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."; } &lt;/script&gt; </code></pre> <p>Hope this can help someone else out. I have searched for days looking for an answer and nothing would work.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload