Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
743 views
in Technique[技术] by (71.8m points)

ruby on rails - Changing songs on jPlayer by clicking a link, hosted on Amazon S3

Hello all and thanks for any help in advance.

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.

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

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.

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.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well it appears that the only issue was a lack of brackets around the mp3: url part of jPlayer("setMedia"....

so it should have been (...).jPlayer("setMedia", {mp3: url}).(...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...