I am trying to integrate a mp3 player in WordPress using the following code:
$(document).ready(function(){
var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
var path_php = "<?php bloginfo('template_directory'); ?>";
$('body').ttwMusicPlayer(myPlaylist, {
autoPlay:false,
description:description,
jPlayer:{
swfPath: path_php+'/plugin/jquery-jplayer'
}
});
});
In a weird way the player is working just in Opera and IE8. The script is correct integrated because it work if i write the absolute path of the blog for the var php_path.
Can help me with what i am missing? Thanks!
later edit: if you have an idea about a different approach of how to load a wp template path in above jquery code, i am open to it.
here is the browser output for the above code:
$(document).ready(function(){
var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
var path_php = "http://localhost/mywebsite/wp-content/themes/mythemename";
$('body').ttwMusicPlayer(myPlaylist, {
autoPlay:false,
description:description,
jPlayer:{
swfPath: path_php+'/plugin/jquery-jplayer'
}
});
});
In wordpress
brings back the plugin url including the domain.
So that should replace the http:// and domain with nothing, leaving you with just the plugin path and jquery-jplayer on the end.
I’m pretty sure
bloginfo('template_directory')
returns an absolute URL and Flash will only load relative URL’s for security reasons.http://codex.wordpress.org/Function_Reference/bloginfo
EDIT:
Ignore my last comment below, try this.
Please change the $ to jQuery instead as WordPress runs in noconflict mode, read more about it here -> http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers
Hey I just wrote a script to convert mp3 links to an audio player: http://www.bottleofbrass.com/?p=85
The Javascript code below uses jQuery to convert mp3 links to a flash player on the fly. It utilizes this flash player: http://flash-mp3-player.net.
$(‘#main a’).each(function(){
if($(this).attr(‘href’)!=undefined){
match=$(this).attr(‘href’).match(/.(mp3)/);
if(match!=null){
href=$(this).attr(‘href’);
text=$(this).text();
player= ”+text+”+
”+
”+
”+
”+
”;
p=$(this).parent();
$(this).remove();
$(p).append(player);
}
}
});