0

I wonder to use SC.oEmbed to play sound from SoundCloud.But when I use it, I always get ERR_FILE_NOT_FOUND error.

I put my Source Code in Jsfiddle: http://jsfiddle.net/n2sVk/, it works OK. But when I save it to a HTML file and open it with Chrome, the error would be observed. The Source Code is shown as below:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
</head>
<body>

    <script src="http://connect.soundcloud.com/sdk.js"></script>

    <div id="wrap"></div>
    <script type="text/javascript">
        SC.initialize({
            client_id: "c202b469a633a7a5b15c9e10b5272b78",
            redirect_uri: "http://connect.soundcloud.com/examples/callback.html"
        });

        SC.connect(function(){
            console.log("connect " + "return"); 
            SC.get("/me", function(me){
            console.log("me.username:" + me.username);
            console.log("me.description:" + me.description);

            SC.get("/tracks", {limit: 1}, function(tracks){
                console.log("get track return");
                track = tracks[0];
                console.log("track.uri: " + track.uri);
                console.log("track.title: " + track.title);
                SC.oEmbed(track.permalink_url, 
                          {auto_play: true},
                          document.getElementById("wrap"));        
                });
            });
        });
    </script>

</body>

Here is the error from Chrome:

GET file://soundcloud.com/oembed.json?auto_play=true&url=http%3A%2F%2Fsoundcloud.com%2Fyung-crusty-beats%2Fmystic-juice net::ERR_FILE_NOT_FOUND sdk.js:1 oEmbed response: null

Lancer
  • 55
  • 5

1 Answers1

1

This happens because when you are testing it locally, you are on "file:///" protocol.

The library's source code is using // in place of the protocol – this lets the library work on both http and https. However, when you access your code from a file as opposed to a webserver, the oembed function will probably not work.

The solution will be to run a local web server, such as Python simple server, which you'd run from the root folder of your project:

python -m SimpleHTTPServer
Community
  • 1
  • 1
Misha Reyzlin
  • 13,736
  • 4
  • 54
  • 63
  • Maybe I have a misunderstand. Do you mean oembed could only be used in server side? My APP is only a Client-side JavaScript Application, so we cannot use SC.oEmbed? – Lancer Jun 05 '14 at 01:57
  • No, there's a difference in how you serve your filse, there's "file protocol" and that doesn't work with all client-side code, eventually your client-side code will have to be served from a web server. – Misha Reyzlin Jun 05 '14 at 06:10
  • It's just about the development environment where you test your local project – Misha Reyzlin Jun 05 '14 at 06:11