在整个页面访问 jplayer 实例以根据用户点击加载数据
我希望能够使用 $("#audio_2ndplaylist").click(function(){ 来允许用户交换 jPlayer 正在使用的 src="" 数据(即包含源 URL 的 JSON 格式数据) )我认为我的主要问题是我不确定如何在我初始化它的位置之外引用这个 jPlayer 对象。 $("#jplayer_id").data("jPlayer") 但这到目前为止对我不起作用
这是我的初始化 jPlayer 的代码:
var data= [ {title:"Cro Magnon Man",
artist:"The Stark Palace",
mp3:'http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3'
},
{title:"Your Face",
artist:"The Stark Palace",
mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
}];
new jPlayerPlaylist({
jPlayer: "#jplayer_id",
}, data,
{
supplied: "webmv, ogv, m4v, oga, mp3, mov, mp4"
}); // end of jPlayerPlaylist instance
这是我的点击代码。(function(){ //立即执行在我的脚本中遵循上述代码:
$('audio_2ndplaylist').click(function() {
var data2=[ {title:"Hidden",
artist:"Miaow",
mp3:"http://www.jplayer.org/audio/mp3/Miaow-02-Hidden.mp3",
},
{title:"Tempered Song",
artist:"Miaow",
mp3:"http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3",
}];
var jplay=$("#jplayer_id").data("jPlayer");
jplay.load(data2);
}); // end of click function
任何人可能对切换此 jPlayer 正在使用的 JSON 对象从“data”与“data2”进行切换将不胜感激,
I'd like to be able to use a $("#audio_2ndplaylist").click(function(){ to allow users to exchange the src="" data that jPlayer is using (i.e., the JSON formatted data containing the source URLs). I think my main issue is that i'm not sure how to reference this jPlayer object outside of where I initialized it. The jPlayer site documentation says to use $("#jplayer_id").data("jPlayer") but this has not worked for me so far.
Here's my code for the initializing the jPlayer:
var data= [ {title:"Cro Magnon Man",
artist:"The Stark Palace",
mp3:'http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3'
},
{title:"Your Face",
artist:"The Stark Palace",
mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
}];
new jPlayerPlaylist({
jPlayer: "#jplayer_id",
}, data,
{
supplied: "webmv, ogv, m4v, oga, mp3, mov, mp4"
}); // end of jPlayerPlaylist instance
And here's my code for the click.(function(){ //which immediately follows the above code in my script:
$('audio_2ndplaylist').click(function() {
var data2=[ {title:"Hidden",
artist:"Miaow",
mp3:"http://www.jplayer.org/audio/mp3/Miaow-02-Hidden.mp3",
},
{title:"Tempered Song",
artist:"Miaow",
mp3:"http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3",
}];
var jplay=$("#jplayer_id").data("jPlayer");
jplay.load(data2);
}); // end of click function
Any help one might have for switching the JSON object this jPlayer is using from "data" with "data2" would be greatly appreciated,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为有几件事:
Csq :jplay 是唯一的公共变量,您不必在第二个脚本中实例化它。
您的两个脚本现在是:
第二个:
希望这会有所帮助:-)
There are several things I think :
Csq : jplay is the only public var, you don't have to instance it in your 2nd script.
Your two scripts are now :
And the second one :
Hoping this will help :-)