Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add SoundCloud support

  • Loading branch information...
commit 617a9716db484a4fdbe56eae82415deffd5d3ff7 1 parent f552b6f
@cshum authored
View
2  config.js
@@ -18,10 +18,12 @@ var requirejs = ({
'scm':{
playback:{
'youtube':'(youtube.com|youtu.be)',
+ 'soundcloud':'^http\:\/\/soundcloud.com',
'soundmanager':'.*'
},
playlist:{
'youtube':'(youtube.com|youtu.be)',
+ 'soundcloud':'^http\:\/\/soundcloud.com',
'rss':'.*'
}
}
View
26 js/playback/soundcloud.js
@@ -0,0 +1,26 @@
+define(['scm','playback/soundmanager!','jquery'],function(SCM,sm,$){
+
+ return {
+ load:function(name, req, callback, config){
+ var consumer_key = "89e7642d86f9241b0d1917ebfae99e38",
+ current;
+ callback({
+ on:function(url,finishCallback){
+ var resolveURL = 'http://api.soundcloud.com/resolve?url=' + url + '&format=json&consumer_key='
+ + consumer_key + '&callback=?';
+ current = $.getJSON(resolveURL, function(track){
+ var url = track.stream_url;
+ url = (url.indexOf("secret_token") == -1) ? url + '?' : url + '&';
+ url += 'consumer_key=' + consumer_key;
+ sm.on(url,finishCallback);
+ });
+ },
+ off:function(){
+ current.abort();
+ sm.off();
+ }
+ });
+ }
+ };
+});
+
View
22 js/playlist/soundcloud.js
@@ -0,0 +1,22 @@
+define(['jquery','song'],function($,Song){
+ var consumer_key = "89e7642d86f9241b0d1917ebfae99e38";
+
+ return {
+ load:function(url, req, callback, config){
+ var resolveURL = 'http://api.soundcloud.com/resolve?url=' + url + '&format=json&consumer_key='
+ + consumer_key + '&callback=?';
+ $.getJSON(resolveURL, function(data){
+ callback($.map(data.tracks,function(track){
+ var url = track.stream_url;
+ url = (url.indexOf("secret_token") == -1) ? url + '?' : url + '&';
+ url += 'consumer_key=' + consumer_key;
+ return new Song({
+ title:track.title,
+ url:url
+ });
+ }));
+ });
+ }
+ }
+});
+
View
6 script.js
@@ -10,9 +10,8 @@
scmHost = scm.substr(0,scm.indexOf('/',10)),
isOutside = !hasFrame || location.href.indexOf("scmplayer=true")>0,
postMessage = function(msg){
- if(!isOutside)
- return window.top.document.getElementById('scmframe')
- .contentWindow.postMessage(msg,scmHost);
+ return window.top.document.getElementById('scmframe')
+ .contentWindow.postMessage(msg,scmHost);
},
postFactory = function(obj,keys){
var keys = keys.split(','),
@@ -31,6 +30,7 @@
}
},
postConfig = function(config){
+ if(!isOutside)
postMessage('SCM.config('+config+')');
},
Please sign in to comment.
Something went wrong with that request. Please try again.