Skip to content

Commit

Permalink
update code snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
Floby committed Dec 27, 2012
1 parent 6a39e74 commit aaa7c4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Here is a code snippet of how to play a track from spotify

var sp = require('../lib/libspotify');
var cred = require('../spotify_key/passwd');
var fs = require('fs');
var spawn = require('child_process').spawn;

var f = fs.createWriteStream('/tmp/bidule.raw');

var session = new sp.Session({
applicationKey: __dirname + '/../spotify_key/spotify_appkey.key'
Expand All @@ -54,6 +58,10 @@ session.once('login', function(err) {
var player = session.getPlayer();
player.load(track);
player.play();

var play = spawn('aplay', ['-c', 2, '-f', 'S16_LE', '-r', '44100']);
player.pipe(play.stdin);

console.log('playing track. end in %s', track.humanDuration);
player.on('data', function(buffer) {
// buffer.length
Expand All @@ -63,6 +71,7 @@ session.once('login', function(err) {
});
player.once('track-end', function() {
console.log('track ended');
f.end();
player.stop();
session.close();
});
Expand Down
9 changes: 9 additions & 0 deletions example/play.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var sp = require('../lib/libspotify');
var cred = require('../spotify_key/passwd');
var fs = require('fs');
var spawn = require('child_process').spawn;

var f = fs.createWriteStream('/tmp/bidule.raw');

var session = new sp.Session({
applicationKey: __dirname + '/../spotify_key/spotify_appkey.key'
Expand All @@ -21,6 +25,10 @@ session.once('login', function(err) {
var player = session.getPlayer();
player.load(track);
player.play();

var play = spawn('aplay', ['-c', 2, '-f', 'S16_LE', '-r', '44100']);
player.pipe(play.stdin);

console.log('playing track. end in %s', track.humanDuration);
player.on('data', function(buffer) {
// buffer.length
Expand All @@ -30,6 +38,7 @@ session.once('login', function(err) {
});
player.once('track-end', function() {
console.log('track ended');
f.end();
player.stop();
session.close();
});
Expand Down

0 comments on commit aaa7c4a

Please sign in to comment.