使用jplayer在单个页面中的多个mp3链接 [英] multiple mp3 links in a single page with jplayer

查看:79
本文介绍了使用jplayer在单个页面中的多个mp3链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中有许多mp3链接,我使用的是jplayer。如何点击单独的链接更新jplayer功能?

In my page there are a number of mp3 links and I use jplayer. How can I update jplayer function to play when clicked the seperate links?

$(document).ready(function() {

 $("#jquery_jplayer_1").jPlayer({

    ready: function(event) {
        $(this).jPlayer("setMedia", {
            mp3: "test_1.mp3",   //my mp3 file

        });
    },
    swfPath: "http://www.jplayer.org/2.1.0/js",
    supplied: "mp3"
  });
});    

我的mp3链接:

<a href="javascript:listen(1);" class="jp-play" ></a>
<a href="javascript:listen(2);" class=" jp-play" ></a>
<a href="javascript:listen(3);" class=" jp-play" ></a>
<a href="javascript:listen(4);" class=" jp-play" ></a>
<a href="javascript:listen(5);" class=" jp-play" ></a>


推荐答案

嘿,你可以做到以下几点。

Hey you can do the following.

我在页面加载时实例化播放器:

I instantiate the player on page load:

jQuery("#jquery_jplayer_1").jPlayer({
swfPath: "http://www.jplayer.org/latest/js/Jplayer.swf",
supplied: "mp3",
wmode: "window",
preload:"auto",
autoPlay: true,
errorAlerts:false,
warningAlerts:false
});

然后在一个监听器中,每个项目都是唯一的,你需要:A)获取跟踪姓名/网址,我想你应该能够解决这个问题。

Then inside a listener, which will be unique for every item, you need to: A) Fetch track name/URL, I guess you should be able to figure this out.

B)将曲目传递给setMedia

B) Pass the track to the setMedia

jQuery("#jquery_jplayer_1").jPlayer("setMedia", {
mp3: "http:xxxx.rackcdn.com/"+track+".MP3"
});

C)播放曲目

jQuery("#jquery_jplayer_1").jPlayer("play");

要获得曲目ID,您需要在可播放的项目上安装听众(也许是一个可玩的课程?)并从那个获得曲目。

To get the track Id you need to install listeners on your playable items(maybe a a playable class?) and get the track from that one.

这篇关于使用jplayer在单个页面中的多个mp3链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆