Directly using pure JWPlayer JS (but NOT WP Plugin)

First of all, I'm not using WP JWPlayer Plugin. (And i don't want it. And thats the another story)


Well in the Template file:

wp_register_script('myJW', get_bloginfo('template_url') . '/jwplayer.js');
wp_enqueue_script('myJW');
?

div id='myJWPlayer'/div
script
jQuery(document).ready(function(){
    jwplayer("myJWPlayer").setup({
        playlist: "http://www.example.com/playlist.xml",
        listbar: {
                position: 'right',
                size: 250
        },
        width: 700,
        height: 400
    });
});
/script

It is not working, since even the jwplayer("myJWPlayer") call is not being triggered.


Note: This codes are perfectly working in pure HTML sites.

Any idea please?

Topic jwplayer templates Wordpress javascript

Category Web


EDIT

http://www.example.com/playlist.xml is not valid playlist url. Also you are missing " at the end of the url.

Please refer to http://www.longtailvideo.com/support/jw-player/28850/using-the-javascript-api for jwplayer usage.

You also need to call

jwplayer().play()

Try this,

wp_register_script('myJW', get_bloginfo('template_url') . '/jwplayer.js',array('jquery'));
wp_enqueue_script('myJW');
?>

<div id='myJWPlayer'></div>
<script>
jQuery(document).ready(function(){
    alert('am called');
    jwplayer("myJWPlayer").setup({
        playlist: "http://www.example.com/playlist.xml,
        listbar: {
                position: 'right',
                size: 250
        },
        width: 700,
        height: 400
    });
});
</script>

Also see browser error log if you receive any error. You can use firebug for firefox, or if you are using chrome just press f12 that will open devlopement console, go to console and reload page. May be you catch some usefull info there.

Also note that it would be wise to register and enqueue script from functions file.


You need to properly enqueue your script. You should hook your script to the

function enqueue_custom_script() {
     wp_register_script('myJW',  get_bloginfo('template_url') . '/jwplayer.js');
    wp_enqueue_script('myJW');
}

add_action( 'wp_enqueue_scripts', 'enqueue_custom_script' );  

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.