javascript - simple play sound from soundcloud by clicking button -


trying stream sound on page soundcloud, said on api, unfortunately there's no sound when i'm click on button. otherwise, when "run" code here or on jsfiddle - works! must problem i'm trying run local disc? how can solve it?

sc.initialize({    client_id: '53902af7a344bb0351898c47bc3d786f'  });     $("#stream").on("click", function(){      sc.stream("/tracks/49712607", function(sound){      sound.play();      });    });
<!doctype html>  <html>  <head>      <title>music</title>      <meta charset="windows-1251">      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>      <script src="http://connect.soundcloud.com/sdk-2.0.0.js"></script>      <script src="script.js"></script>  </head>  <body>         <div id='player'>player                <input type="button" href="#" id="stream" class="big button" value="stream again, sam" />         </div>   </body>   </html>

you need execute call sdk while files hosted on web server. can have web server running form local machine.

the problem trying run things filesystem. when doing so, error: ns_error_dom_bad_uri: access restricted uri denied

to ensure have error, please try basic example soundcloud.

see this question.

what technology choose depends on feel comfortable with...

for instance of local apps node.js. maybe simplest way use http-server noted in comment.

launch on command line with: http-server <your-directory> -o. -o default browser open , list files in your-directory.

notice soundcloud docs using jquery .live() function call but deprecated! made code work despite dom not being ready yet.

here, want use regular .on() function , have binding of click event handler done once dom ready. use $(document).ready(function() { ... });

here's code used.

<!doctype html> <html> <head>     <title>music</title>     <meta charset="windows-1251">     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     <script src="//connect.soundcloud.com/sdk-2.0.0.js"></script>     <script>     sc.initialize({         client_id: "53902af7a344bb0351898c47bc3d786f"     });      $(document).ready(function() {         $("#stream").on("click", function(){             sc.stream("/tracks/49712607", function(sound){                 sound.play();             });         });     });     </script> </head> <body>     <div id='player'>player                <input type="button" href="#" id="stream" class="big button" value="stream again, sam" />     </div> </body> </html> 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -