WordPress.org

Ready to get started?Download WordPress

Forums

JW Player for Flash & HTML5 Video
Targeting videos with javascript (10 posts)

  1. hiramhibbard
    Member
    Posted 1 year ago #

    Hi there,

    I'm trying to figure out how to target the video to check when it has finished playing. I need to do something along the lines of

    onComplete: function() {
    alert( 'video complete')
    }

    Not exactly that, but you get the idea. I know I can use shortcode like so:
    [jwplayer mediaid="221" onComplete="function() {alert('video complete');}"]
    but the problem with that approach is that the client has to add that into the shortcode every time they upload a video to a post, which is impractical. I need to be able to target the video with javascript from the template file.

    Did a lot of Googling but was unable to find an actual answer to this.

    Thanks!

    http://wordpress.org/extend/plugins/jw-player-plugin-for-wordpress/

  2. JW Player
    Member
    Plugin Author

    Posted 1 year ago #

    The best way to do this with the plugin is to do this in the shortcode. Otherwise, you are going to have to hack this into your site's template.

  3. hiramhibbard
    Member
    Posted 1 year ago #

    Like I said, having to type that into the shortcode every time is impractical. Looks like I'll have to hack the plugin :-/

    I would definitely recommend adding the ability to add callbacks without typing it into the shortcode as a feature.

  4. JW Player
    Member
    Plugin Author

    Posted 1 year ago #

    How would it be easier for the client to update the events in a hacked version of the plugin than via the recommended, and documented, method?

  5. hiramhibbard
    Member
    Posted 1 year ago #

    It would be easier if I could just target the video via javascript from a template file. Obviously much easier than if a non-javascript has to remember to paste a bunch of javascript into a shortcode, instead of just uploading the video and clicking "insert into post".

    I definitely don't want to hack the plugin, but it doesn't make sense to force the client to have to do that extra work when normally I would just write some javascript that they would never have to touch (like with the non-wordpress version of JW player)

  6. JW Player
    Member
    Plugin Author

    Posted 1 year ago #

    You could always write that into the shortcode as well though, it works.

  7. hiramhibbard
    Member
    Posted 1 year ago #

    If you mean the code in the plugin that generates the shortcode, then yeah that's what I'll probably have to do. If you're just talking about using the shortcode in a post, that's what I'm trying to avoid, as it won't be me adding the videos, it will be non-js savvy editors. I'm not sure I'm explaining my issue well enough, but that's ok, I'm on the right track looking through the plugin code now.

  8. JW Player
    Member
    Plugin Author

    Posted 1 year ago #

    Yeah

  9. hiramhibbard
    Member
    Posted 1 year ago #

    For others who have this problem, you don't need to have the callbacks in the shortcode, nor do you have to hack the plugin as suggested. The js just needs to come AFTER the javascript generated by the plugin, which is why it wasn't working for me. In my case, just adding

    <script>
    jwplayer('jwplayer-1').onComplete(function() {
    jQuery.colorbox.close();
    })
    </script>

    worked for me (to close a colorbox once the video completed).

  10. JW Player
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for sharing!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.