-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathPlayer.js
More file actions
54 lines (42 loc) · 1.51 KB
/
Player.js
File metadata and controls
54 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var b = require('bindings')('spotify.node');
var sp = require('./libspotify');
var util = require('util');
var assert = require('assert');
var stream = require('stream');
function Player (session) {
assert(undefined !== session, "missing parameter session");
assert(session instanceof sp.Session, "parameter is not a session");
this._session = session;
var self = this;
// Tell spotify that we're ready for more data
this._read = function() {
b.session_player_stream_resume();
};
this._session._sp_session.music_delivery = function(buffer) {
// Readable.push returns whether or not we should push more data,
// so we're returning that value so the underlying code knows what to do
return self.push(buffer);
};
this._session._sp_session.end_of_track = function() {
self.emit('track-end');
};
stream.Readable.call(this);
}
util.inherits(Player, stream.Readable);
Player.prototype.load = function load(track) {
assert(track instanceof sp.Track);
b.session_player_load(this._session._sp_session, track._sp_object);
};
Player.prototype.seek = function play(position) {
b.session_player_seek(this._session._sp_session, position);
};
Player.prototype.play = function play() {
b.session_player_play(this._session._sp_session, true);
};
Player.prototype.stop = function stop() {
b.session_player_play(this._session._sp_session, false);
};
Player.prototype.flush = function flush() {
b.player_flush_audio(this._session._sp_session);
};
module.exports = Player;