在整个页面访问 jplayer 实例以根据用户点击加载数据

发布于 2024-12-04 17:06:10 字数 1259 浏览 2 评论 0原文

我希望能够使用 $("#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉 2024-12-11 17:06:10

我认为有几件事:

  1. 您没有命名您的jPlayerPlaylist(例如var jplay = new jPlayerPlaylist();)。像这样,您可以像第二个脚本中一样访问 jPlayerPlaylist 实例。
  2. 添加一些曲目的正确函数是 add() 或 setPlaylist()

Csq :jplay 是唯一的公共变量,您不必在第二个脚本中实例化它。

您的两个脚本现在是:

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",
                }];

var jplay = new jPlayerPlaylist({
    jPlayer: "#jplayer_id",
    }, data,
    {
        supplied: "webmv, ogv, m4v, oga, mp3, mov, mp4" 
}); // end of jPlayerPlaylist instance

第二个:

$('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",
}]; 

jplay.add(data2); 

}); // end of click function

希望这会有所帮助:-)

There are several things I think :

  1. You don't name your jPlayerPlaylist (like var jplay = new jPlayerPlaylist(); for instance). Like this your may access your jPlayerPlaylist instance as in your second script.
  2. The right function to add some tracks is add() or setPlaylist()

Csq : jplay is the only public var, you don't have to instance it in your 2nd script.

Your two scripts are now :

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",
                }];

var jplay = new jPlayerPlaylist({
    jPlayer: "#jplayer_id",
    }, data,
    {
        supplied: "webmv, ogv, m4v, oga, mp3, mov, mp4" 
}); // end of jPlayerPlaylist instance

And the second one :

$('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",
}]; 

jplay.add(data2); 

}); // end of click function

Hoping this will help :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文