Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Installation
------------

``` bash
$ npm install spotify-web
$ npm install spotify-web --save
```


Expand All @@ -23,32 +23,30 @@ Here's an example of logging in to the Spotify server and creating a session. Th
requesting the metadata for a given track URI, and playing the track audio file
through the speakers:

``` javascript
var lame = require('lame');
var Speaker = require('speaker');
var Spotify = require('spotify-web');
var uri = process.argv[2] || 'spotify:track:6tdp8sdXrXlPV6AZZN2PE8';
```js
const lame = require('lame');
const Speaker = require('speaker');
const Spotify = require('spotify-web');
const uri = process.argv[2] || 'spotify:track:6tdp8sdXrXlPV6AZZN2PE8';

// Spotify credentials...
var username = process.env.USERNAME;
var password = process.env.PASSWORD;
const username = process.env.USERNAME;
const password = process.env.PASSWORD;

Spotify.login(username, password, function (err, spotify) {
Spotify.login(username, password, (err, spotify) => {
if (err) throw err;

// first get a "Track" instance from the track URI
spotify.get(uri, function (err, track) {
if (err) throw err;
console.log('Playing: %s - %s', track.artist[0].name, track.name);
spotify.get(uri, (err, track) => {
   if (err) throw err;

   console.log('Playing: %s - %s', track.artist[0].name, track.name);

// play() returns a readable stream of MP3 audio data
track.play()
.pipe(new lame.Decoder())
.pipe(new Speaker())
.on('finish', function () {
spotify.disconnect();
});

.on('finish', () => spotify.disconnect());
});
});
```
Expand Down