Brandon Pfeiffer avatar Brandon Pfeiffer committed 9f9b0dd

+ ‘index.html’
+ ‘manifest.json’
+ ‘tutorial.css’
+ ‘tutorial.js’

Comments (0)

Files changed (4)

+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>My First App</title>
+	<link rel="stylesheet" href="sp://import/css/adam.css">
+	<link rel="stylesheet" href="tutorial.css">
+</head>
+<body onload="sp = getSpotifyApi(1); tutorial = sp.require('tutorial'); tutorial.init();">
+<h1 id="header">Hello, world!</h1>
+</body>
+</html>
+{
+	"BundleType": "Application",
+	"BundleIdentifier": "tutorial",
+	"AppIcon": {
+		"36x18": "tutorial.png"
+	},
+	"AppName": {
+		"en": "Tutorial"
+	},
+	"SupportedLanguages": [
+		"en"
+	],
+	"RequiredPermissions": [
+		"http://ws.audioscrobbler.com"
+	]
+}
+h1 {
+	text-align: center;
+	font-size: 24px;
+	padding: 20px;
+}
+var sp = getSpotifyApi(1);
+var models = sp.require('sp://import/scripts/api/models');
+var player = models.player;
+
+exports.init = init;
+
+function init() {
+
+	updatePageWithTrackDetails();
+
+	player.observe(models.EVENT.CHANGE, function (e) {
+
+		// Only update the page if the track changed
+		if (e.data.curtrack == true) {
+			updatePageWithTrackDetails();
+		}
+	});
+
+	searchLastFMForEvents("stockholm");
+}
+
+function updatePageWithTrackDetails() {
+	
+	var header = document.getElementById("header");
+
+	// This will be null if nothing is playing.
+	var playerTrackInfo = player.track;
+
+	if (playerTrackInfo == null) {
+		header.innerText = "Nothing playing!";
+	} else {
+		var track = playerTrackInfo.data;
+		header.innerHTML = track.name + " on the album " + track.album.name + " by " + track.album.artist.name + ".";
+	}
+}
+
+function searchLastFMForEvents(city) {
+
+	var req = new XMLHttpRequest();
+	req.open("GET", "http://ws.audioscrobbler.com/2.0/?method=geo.getevents&location=" + city + "&api_key=YOUR_KEY_HERE", true);
+
+	req.onreadystatechange = function() {
+
+		console.log(req.status);
+
+   		if (req.readyState == 4) {
+    		if (req.status == 200) {
+       			console.log("Search complete!");
+       			console.log(req.responseText);
+     		}
+   		}
+  	};
+
+	req.send();
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.