Video End Event in Rails

How do you call an event or action after a video has finished playing? For example, I wanted a “Continue” button to appear after the video has finished.  Searching around this was a bit hard to find, so hopefully this post will help some people.

There is an “onended" function that you can call on the video object. This is how I do it.

Here’s the jQuery

$("#myVideo").bind("ended", function() {
   //whatever you want to do when the video ends
});

In Rails, here’s the coffeescript I use

$("#myVideo").bind "ended", ->
    # whatever you want to do when the video ends

Make sure the video tag in the html has the id that you’re referencing in the javascript/coffeescript.

<%= video_tag('FMCintro.mp4', size: "724x500", controls: true, id: "myVideo") %>

credit to this StackOverflow question. This one might be helpful too.

Advertisements

One Response to Video End Event in Rails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: