2

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' 
                }
            });
        });
4

4 回答 4

0

我很确定会bloginfo('template_directory')返回一个绝对 URL,出于安全原因,Flash 只会加载相对 URL。

http://codex.wordpress.org/Function_Reference/bloginfo

编辑:

忽略我下面的最后一条评论,试试这个。

<?php print str_replace(get_bloginfo('url'), '', get_bloginfo('template_directory'))?>
于 2011-08-26T09:08:23.997 回答
0

嘿,我刚刚写了一个脚本来将 mp3 链接转换为音频播放器: http: //www.bottleofbrass.com/?p=85

下面的 Javascript 代码使用 jQuery 将 mp3 链接即时转换为 Flash 播放器。它利用了这个 Flash 播放器: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(播放器); } } });
于 2011-12-29T17:56:26.160 回答
0

请改为将 $ 更改为 jQuery,因为 Wordpress 在无冲突模式下运行,请在此处阅读更多信息 -> http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers

于 2011-08-26T12:14:52.840 回答
0

在wordpress中

plugins_url()

带回包含域的插件 url。

$(document).ready(function(){
    var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
        var path_php = "<?php print plugins_url(); ?>";

    $('body').ttwMusicPlayer(myPlaylist, {
        autoPlay:false, 
        description:description,
        jPlayer:{
            swfPath: path_php.match(/http:\/\/[^\/]+(.*)/)[1]+'jquery-jplayer' 
        }
    });
});

所以应该什么都没有替换 http:// 和域,最后只剩下插件路径和 jquery-jplayer。

于 2011-08-26T09:24:07.037 回答