Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

resolve tracks over ssl when needed

added test for api urls based tracks
  • Loading branch information...
commit 370d50025c6da97cd5db73f699ce098d2c2b5183 1 parent 96fd42a
Matas authored
View
2  css/sc-player-minimal/structure.css
@@ -92,7 +92,7 @@
position: absolute;
top: 0;
width: 0;
- -webkit-transition: width 1s linear;
+ -webkit-transition: width 0.1s linear;
}
.sc-scrubber .sc-time-indicators{
View
4 examples/sc-player-minimal.html
@@ -15,11 +15,11 @@
<div class="post">
<a href="http://soundcloud.com/matas/hobnotropic" class="sc-player">My dub track</a>
- <a href="http://soundcloud.com/sarahweis/special" class="sc-player special">Special player</a>
+ <a href="http://soundcloud.com/chamanisme/special" class="sc-player special">Special player</a>
<a href="http://soundcloud.com/forss/forss-vs-borg-deadline-live-in-milan-2004" class="sc-player">Forss</a>
<a href="http://soundcloud.com/matas/matas-petrikas-live-at-gravity-club-30-05-2008" class="sc-player">My dub track</a>
<a href="http://soundcloud.com/matas/goldfrapp-little-bird-matas-ornitologic-remix" class="sc-player">Pumpkins Track</a>
- <a href="http://soundcloud.com/matas/on-the-bridge" class="sc-player">Oxxo</a>
+ <a href="https://soundcloud.com/matas/on-the-bridge" class="sc-player">Secure track</a>
<a href="http://soundcloud.com/matas/laimis-vilkoncius-ar-issaugosi-mano-meile/s-vkgFz" class="sc-player">Secret track</a>
</div>
View
19 index.html
@@ -8,12 +8,21 @@
<meta name="author" content="Matas Petrikas">
</head>
<body>
- <h1>SoundCloud Custom Player Skins</h1>
+ <h1>SoundCloud Custom Player</h1>
<ul>
- <li><a href="examples/sc-player-standard.html" title="sc-player-standard">Standard</a></li>
- <li><a href="examples/sc-player-artwork.html" title="sc-player-artwork">Artwork</a></li>
- <li><a href="examples/sc-player-minimal.html" title="sc-player-minimal">Minimal</a></li>
- <li><a href="examples/sc-player-red.html" title="sc-player-red">Red</a></li>
+ <li>Skins
+ <ul>
+ <li><a href="examples/sc-player-standard.html" title="sc-player-standard">Standard</a></li>
+ <li><a href="examples/sc-player-artwork.html" title="sc-player-artwork">Artwork</a></li>
+ <li><a href="examples/sc-player-minimal.html" title="sc-player-minimal">Minimal</a></li>
+ <li><a href="examples/sc-player-red.html" title="sc-player-red">Red</a></li>
+ </ul>
+ </li>
+ <li>Other
+ <ul>
+ <li><a href="test/" title="Unit Test page">Unit Tests</a></li>
+ </ul>
+ </li>
</ul>
</body>
</html>
View
19 js/sc-player.js
@@ -49,8 +49,23 @@
}
},
domain = useSandBox ? 'sandbox-soundcloud.com' : 'soundcloud.com',
+ secureDocument = (document.location.protocol === 'https:'),
+ // convert a SoundCloud resource URL to an API URL
scApiUrl = function(url, apiKey) {
- return (/api\./.test(url) ? url + '?' : 'http://api.' + domain +'/resolve?url=' + url + '&') + 'format=json&consumer_key=' + apiKey +'&callback=?';
+ var resolver = ( secureDocument || (/^https/i).test(url) ? 'https' : 'http') + '://api.' + domain + '/resolve?url=',
+ params = 'format=json&consumer_key=' + apiKey +'&callback=?';
+
+ // force the secure url in the secure environment
+ if( secureDocument ) {
+ url = url.replace(/^http:/, 'https:');
+ }
+
+ // check if it's already a resolved api url
+ if ( (/api\./).test(url) ) {
+ return url + '?' + params;
+ } else {
+ return resolver + url + '&' + params;
+ }
};
// TODO Expose the audio engine, so it can be unit-tested
@@ -550,7 +565,7 @@
$.scPlayer.stopAll = function() {
$('.sc-player.playing a.sc-pause').click();
};
-
+
// destroy all the players and audio engine, usefull when reloading part of the page and audio has to stop
$.scPlayer.destroy = function() {
$('.sc-player, .sc-player-engine-container').remove();
View
43 test/sc-player-tests.js
@@ -25,6 +25,14 @@ mockList = [
proxy: 'fixtures/hobnotropic.json'
},
{
+ url: 'https://soundcloud.com/matas/hobnotropic',
+ proxy: 'fixtures/hobnotropic.json'
+ },
+ {
+ url: 'http://api.soundcloud.com/tracks/49931',
+ proxy: 'fixtures/hobnotropic.json'
+ },
+ {
url: 'http://soundcloud.com/forss/sets/soulhack',
proxy: 'fixtures/soulhack.json'
},
@@ -216,6 +224,41 @@ asyncTest('multiple links', 3, function() {
});
+asyncTest('api url track', 3, function() {
+
+ $(document).one('onPlayerInit', function(event) {
+ var $player = $(event.target);
+ equal($player.find('.sc-trackslist li').length, 1, "All the tracks are in the list");
+ equal($player.find('.sc-trackslist li.active a').text(), "Hobnotropic", "First track is selected and has correct title");
+ equal($player.find('.sc-trackslist li:eq(0) .sc-track-duration').text(), "8.09", "Track duration is correct in the tracklist");
+ start();
+ });
+
+ var $link = $('<a href="http://api.soundcloud.com/tracks/49931">Matas hobnotropic</a>');
+
+ $("#qunit-fixture").append($link);
+
+ $link.scPlayer();
+
+});
+
+asyncTest('ssl track', 2, function() {
+
+ $(document).one('onPlayerInit', function(event) {
+ var $player = $(event.target);
+ equal($player.find('.sc-trackslist li').length, 1, "All the tracks are in the list");
+ equal($player.find('.sc-trackslist li.active a').text(), "Hobnotropic", "First track is selected and has correct title");
+ start();
+ });
+
+ var $link = $('<a href="https://soundcloud.com/matas/hobnotropic">Matas hobnotropic</a>');
+
+ $("#qunit-fixture").append($link);
+
+ $link.scPlayer();
+
+});
+
module('options', {
setup: function() {
Please sign in to comment.
Something went wrong with that request. Please try again.