Skip to content

Instantly share code, notes, and snippets.

View mager's full-sized avatar
🏠
Working from home

Mager mager

🏠
Working from home
View GitHub Profile
@mager
mager / spotify-apps-tutorial-playlist_mosaic.js
Created March 10, 2012 18:56
Spotify Apps API - Show a playlist mosaic image
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
var views = sp.require("sp://import/scripts/api/views");
var playlistURL = 'spotify:user:magerleagues:playlist:5CZ3KO3EExplZOzHDMzgym';
var playlist = models.Playlist.fromURI(playlistURL);
playlist.observe(models.EVENT.CHANGE, function() {
var mosaic = new views.Image(playlist.image);
mosaic.node.style.width = '300px';
@mager
mager / spotify-apps-sandbox-top_artists_tracks.js
Created February 25, 2012 22:10
Spotify Apps API - Get the top five tracks from five artists (JS)
/* Instantiate the global sp object; include models & views */
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
var views = sp.require("sp://import/scripts/api/views");
var artists = ['Frank Sinatra', 'Drake', 'T-Pain', 'The Lonely Island', 'Avan Lava'];
var playlist = [];
var done = 0;
@mager
mager / spotify-apps-sandbox-share.html
Created February 11, 2012 22:51
Spotify Apps API - Show "Share" popup (HTML)
<div id="share"></div>
@mager
mager / spotify-apps-sandbox-share.js
Created February 11, 2012 22:50
Spotify Apps API - Show "Share" popup
/* Instantiate the global sp object; include models & views */
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
/* The <div /> that will contain the popup */
var element = $('#share');
/* The Spotify URI of the content you want to share */
var content = 'spotify:track:76a6mUM5r7VPexAj37TLjo';
@mager
mager / spotify-apps-sandbox-creating_tabs.js
Created February 11, 2012 20:38
Spotify Apps API - Handling arguments and creating navigational tabs
sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
tabs(); // See function definition below
/* When a user clicks a tab, the "arguments" property on the
* Application object changes, and the tabs() function fires */
models.application.observe(models.EVENT.ARGUMENTSCHANGED, tabs);
function tabs() {
@mager
mager / spotify-apps-sandbox-creating_tabs.json
Created February 11, 2012 20:51
Spotify Apps API - Handling arguments and creating navigational tabs (manifest.json)
{
...
"DefaultTabs": [
{
"arguments": "index",
"title": {
"en": "Home"
}
},
{
@mager
mager / spotify-apps-sandbox-creating_tabs.html
Created February 11, 2012 20:54
Spotify Apps API - Handling arguments and creating navigational tabs (HTML)
<div id="index">
<!-- This content will show up in the "Home" tab -->
</div>
<div id="tabs">
<!-- This content will show up in the "How to use tabs" tab -->
</div>
@mager
mager / spotify-apps-sandbox-player+list.js
Created February 11, 2012 18:01
Spotify Apps API - Play a list of songs (JS)
/* Instantiate the global sp object; include models & views */
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
var views = sp.require("sp://import/scripts/api/views");
/* Create an array of tracks from the user's library */
var tracks = models.library.tracks;
/* Create a temporary playlist and fill it with tracks
* from the previous query */
@mager
mager / spotify-apps-sandbox-manifest.json
Created February 10, 2012 20:46
Spotify Apps API - Creating your manifest.json file
{
"AppDescription": {
"en": "A tutorial app for Spotify Apps API"
},
"AppIcon": {
"36x18": "tutorial.png"
},
"AppName": {
"en": "Spotify Sandbox"
},
@mager
mager / spotify-apps-sandbox-click_to_play.css
Created February 10, 2012 19:31
Spotify Apps API - Play/pause with an HTML element (CSS)
<style>
#play-me {
width:600px;
height:40px;
border:1px solid #333;
font:italic 2.5em Georgia, serif;
text-align:center;color:#000;
}
</style>