From 7cb899a4d44a70743b109fc44b0468362005655e Mon Sep 17 00:00:00 2001 From: jmanero Date: Fri, 15 Aug 2014 16:05:43 -0400 Subject: [PATCH 1/2] Adding seek to player --- lib/Player.js | 4 ++++ src/player.cc | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Player.js b/lib/Player.js index 74f1bf6..4052444 100644 --- a/lib/Player.js +++ b/lib/Player.js @@ -36,6 +36,10 @@ Player.prototype.load = function load(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 * 1000); +}; + Player.prototype.play = function play() { b.session_player_play(this._session._sp_session, true); }; diff --git a/src/player.cc b/src/player.cc index cbca136..684b821 100644 --- a/src/player.cc +++ b/src/player.cc @@ -60,7 +60,7 @@ extern int call_music_delivery_callback(sp_session* session, const sp_audioforma audio_fifo_data_t *afd; size_t s; - if (num_frames == 0) { + if (num_frames == 0) { return 0; // Audio discontinuity, do nothing } @@ -145,7 +145,6 @@ static void read_delivered_music(uv_timer_t* handle, int status) { return; } - /** * Load the given track in the player of the given session */ @@ -166,6 +165,24 @@ static Handle Session_Player_Load(const Arguments& args) { return scope.Close(Undefined()); } +/** + * Seek to the sepcified second + */ +static Handle Session_Player_Seek(const Arguments& args) { + HandleScope scope; + + assert(args.Length() == 2); + assert(args[0]->IsObject()); + assert(args[1]->IsNumber()); + + ObjectHandle* session = ObjectHandle::Unwrap(args[0]); + + sp_error error = sp_session_player_seek(session->pointer, args[1]->ToInt32()->Value()); + NSP_THROW_IF_ERROR(error); + + return scope.Close(Undefined()); +} + /** * starts playing */ @@ -201,6 +218,7 @@ static uv_timer_t read_music_handle; void nsp::init_player(Handle target) { NODE_SET_METHOD(target, "session_player_load", Session_Player_Load); + NODE_SET_METHOD(target, "session_player_seek", Session_Player_Seek); NODE_SET_METHOD(target, "session_player_play", Session_Player_Play); NODE_SET_METHOD(target, "session_player_stream_resume", Session_Player_Stream_Resume); From 0b9f69eaa2608b284f1ef3d32c010cf34fc42f83 Mon Sep 17 00:00:00 2001 From: jmanero Date: Sun, 17 Aug 2014 14:07:07 -0400 Subject: [PATCH 2/2] Don't multuply seek position by 1000 --- lib/Player.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Player.js b/lib/Player.js index 4052444..1d8b8a4 100644 --- a/lib/Player.js +++ b/lib/Player.js @@ -37,7 +37,7 @@ Player.prototype.load = function load(track) { }; Player.prototype.seek = function play(position) { - b.session_player_seek(this._session._sp_session, position * 1000); + b.session_player_seek(this._session._sp_session, position); }; Player.prototype.play = function play() {