通过单击托管在 Amazon S3 上的链接更改 jPlayer 上的歌曲 [英] Changing songs on jPlayer by clicking a link, hosted on Amazon S3
问题描述
大家好,感谢您提前提供帮助.
Hello all and thanks for any help in advance.
我有一个 ruby on rails 应用程序,我试图在其中通过托管在 S3 上的 jPlayer 流式传输音频.到目前为止,我上传文件或使用播放器内置的浏览器播放音频文件都没有问题,甚至让 jPlayer 使用 S3 上的歌曲进行初始化.当我开始更换歌曲时,问题就出现了.
I have a ruby on rails application in which I am attempting to stream audio through jPlayer, which is hosted on S3. So far I have no problem uploading files or using the browsers built in player to play audio files, or even getting jPlayer to initialize with a song that is on S3. The issue comes when I get into changing songs.
我像这样初始化 jPlayer:
I initialize jPlayer like this:
$('a.html5').click(function() {
var url = $(this).attr('href');
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3: url
});
},
swfPath: "javascripts",
supplied: "mp3",
wmode: "window"
});
return false;
});
mp3: url 指向 S3 URL 的地方(这一切都很好).
where the mp3: url points to the S3 URL (this all works just fine).
这允许我从链接列表中选择一首歌曲,它加载并开始播放没有问题.
This allows me to select a song from a list of links, and it loads up and starts playing no problem.
问题是,当我尝试更改歌曲时,出现访问控制允许来源错误.所以我尝试了以下方法:
The issue is that when I try to change songs, I get an access-control-allow-origin error. So I tried the following:
$('a.html5').click(function() {
var url = $(this).attr('href');
$("#jquery_jplayer_1").jPlayer("setMedia", mp3: url).jPlayer("play");
return false;
});
这仍然给我一个访问控制允许来源错误.几个小时以来,我一直将头撞在墙上,试图弄清楚这一点,但一无所获.
This still gives me an access-control-allow-origin error. I have been pounding my head against the wall for hours trying to figure this out and nothing.
所以基本上总结一下,我可以初始化 jPlayer 并播放一首歌就好了,但是当我想换一首歌时,access-control-allow-origin 错误毁了我的一天.
So basically a summary is that I can initialize jPlayer and play a song just fine, but when I want to go change a song, access-control-allow-origin errors ruin my day.
有什么想法吗?
推荐答案
看来唯一的问题是 mp3: url part of jPlayer("setMedia"....
Well it appears that the only issue was a lack of brackets around the mp3: url part of jPlayer("setMedia"....
所以它应该是 (...).jPlayer("setMedia", {mp3: url}).(...)
这篇关于通过单击托管在 Amazon S3 上的链接更改 jPlayer 上的歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!