Skip to content

Instantly share code, notes, and snippets.

@MrMitch
Created August 5, 2012 01:02
Show Gist options
  • Save MrMitch/3260931 to your computer and use it in GitHub Desktop.
Save MrMitch/3260931 to your computer and use it in GitHub Desktop.
crescendo API

API Methods

First of all, you need to instanciate the player:

var crescendo = $('#my-player').crescendo(options); 

Here are the default option's value:

var options = {
    autoPlay: false,
    volume: 70,
    endPoint: 'crescendo.html', // the player template
    buttons: {
        play: true,
        stop: true,
        loop: false,
        volume: true
    }
};

crescendo.load()

Load a song in crescendo.
There are several ways of loading a song.

When you already know all the song's info

var song = {
    title: 'Factum Par Fictio',
    artist: 'Revolution Void',
    album: 'Increase the Dosage',
    cover: 'http://api.jamendo.com/get2/image/album/redirect/?id=15656&imagesize=150',
    urls: [
        'http://api.jamendo.com/get2/stream/track/redirect/?id=15656&streamencoding=mp31',
        'http://api.jamendo.com/get2/stream/track/redirect/?id=15656&streamencoding=ogg2'
    ],
    host: 'jamendo'
};

crescendo.load(song);

When you need to fetch them from a web-service

This method requires that you know the song's UID.

var songUID = 15656; // can be a string or an integer
var host = 'jamendo';

crescendo.load(songUID, host); 

crescendo.search()

Search for a song on a web-service a web-service, providing a query string.
This method returns an array containing javascript object that can immediatly be passed to the play() method.

Here again, several ways of doing so.

Using a natively supported service

crescendo natively supports Jamendo, SoundCloud, TinySong & Grooveshark.

// Jamendo
var results = crescendo.search('jamendo', 'revolution void factum par fictio');

// TinySong
var results = crescendo.search('tinysong', 'archive dangervisit');

/**
 * SoundCloud and Grooveshark require an API token ;)
 */
// SoundCloud
var token = 'aefcd765fecda877876dfac786faf';
var results = crescendo.search('soundcloud', 'muse darkshines', token);

// Grooveshark
var token = '765543876gfcaddacfgafc8767';
var results = crescendo.search('grooveshark', 'ratm born of a broken man', token);

Using a custom service

The search() method also allows you to query a custom service.

The service must send a JSON encoded single array or single object.
No special processing will be executed on this response and the search() method will only return the decoded array/object.

var endPoint = 'http://my-music-service.you/search';
var results = crescendo.search(endPoint, 'sting englishman in new york');

crescendo.play()

Play a song previously loaded.

crescendo.pause()

Pause the currently playing song.

crescendo.stop()

Stop the currently playing/paused song.

crescendo.loop(bool)

Toggle song looping.

crescendo.setVolume(int)

Change the volume level.

crescendo.reset()

Reset the player with the options passed to $('#my-player').crescendo();.

Events

  • onCreate
  • onLoad
  • onLoadFinished
  • onPlay
  • onPause
  • onStop
  • onVolumeUpdate
  • onReset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment