The ToneDen SDK is loaded asynchronously, which means your page doesn't have to wait for the SDK to load before rendering.
This means that loading it is a little more complicated than just including a <script>
tag. Don't worry though, we've taken care of all the complicated stuff for you.
Just copy the snippet below into your HTML page, enter your SoundCloud consumer key, and replace the commented portion with your code calling the SDK.
If you don't have a SoundCloud consumer key, you can create one here.
<script>
(function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = "//sd.toneden.io/production/v2/toneden.loader.js"
var entry = document.getElementsByTagName("script")[0];
entry.parentNode.insertBefore(script, entry);
}());
ToneDenReady = window.ToneDenReady || [];
ToneDenReady.push(function() {
ToneDen.configure({
soundcloudConsumerKey: '<YOUR SOUNDCLOUD CONSUMER KEY HERE>'
});
// call SDK functions (ToneDen.player.create(), etc.)
});
</script>
A pure JS customizable audio player for your SoundCloud.
JS API, responsive, customizable. Demo at https://www.toneden.io/player.
Sample Embed Code:
<script>
(function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = "//sd.toneden.io/production/v2/toneden.loader.js"
var entry = document.getElementsByTagName("script")[0];
entry.parentNode.insertBefore(script, entry);
}());
ToneDenReady = window.ToneDenReady || [];
ToneDenReady.push(function() {
ToneDen.configure({
soundcloudConsumerKey: '<YOUR SOUNDCLOUD CONSUMER KEY HERE>'
});
// This is where all the action happens:
ToneDen.player.create({
dom: "#player",
eq: "waves",
skin: "light",
tracksPerArtist: 4,
urls: [
"https://soundcloud.com/mutantbreakz/blacklist-vs-alt-a-fire"
]
});
});
</script>
Documentation coming soon!
ToneDen
Player Instance
play
is true.index
.Sample API Usage:
ToneDen.player.getInstanceByDom("#player").togglePause(false); // The player will start playing, if it isn't already.
ToneDen.player.getInstanceByDom("#player").togglePause(true); // The player will pause.
ToneDen.player.getInstanceByDom("#player").next(); // Play the next track in the list.
127.0.0.1 publisher.dev
127.0.0.1 widget.dev
<VirtualHost *:80>
DocumentRoot "<repo location>/toneden-sdk/test"
ServerName publisher.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "<repo location>/toneden-sdk"
ServerName widget.dev
</VirtualHost>
npm install
in the root directory.We use Webpack to compile the player and all of it's dependencies into a single file.
When you run grunt
from the root directory, the Webpack dev server will start. From this point on, any changes you make
to files in the repo will cause Webpack to rebuild /toneden.js and /toneden.loader.js.
Don't use files built by the webpack dev server in production- they're huge! Run grunt --production to build a minified version.
grunt --dev
will compile a readable, debug-friendly version of the scripts, while grunt --production
will make a minified version.
The loader/ directory contains the scripts that manage (surprise!) loading the SDK when embedded in a webpage. You probably won't have to touch anything in this directory, but here's how it works:
The loader script (toneden.loader.js) uses webpack to asynchronously load the SDK script (toneden.js) from the ToneDen CDN. This system allows embedding pages to include (either asynchronously or synchronously) the relatively small loading script, which then loads the much larger SDK files in a non-blocking way. When the SDK has been loaded, the loader calls all the functions in the global ToneDenReady array, allowing developers to access the functionality of the SDK. (Inspired by/copied from the Shootitlive folks, who are way smarter than me!)
The sdk/ directory contains all the good stuff. The file index.js is the hub of the action. It loads all the functions of the SDK (currently only the player) as dependencies, and returns them so that they can be attached to the global ToneDen object.
You can contact us on GitHub or on Twitter: @tonedenmusic