Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding seek to player #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions lib/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Player.prototype.play = function play() {
b.session_player_play(this._session._sp_session, true);
};
Expand Down
22 changes: 20 additions & 2 deletions src/player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -166,6 +165,24 @@ static Handle<Value> Session_Player_Load(const Arguments& args) {
return scope.Close(Undefined());
}

/**
* Seek to the sepcified second
*/
static Handle<Value> Session_Player_Seek(const Arguments& args) {
HandleScope scope;

assert(args.Length() == 2);
assert(args[0]->IsObject());
assert(args[1]->IsNumber());

ObjectHandle<sp_session>* session = ObjectHandle<sp_session>::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
*/
Expand Down Expand Up @@ -201,6 +218,7 @@ static uv_timer_t read_music_handle;

void nsp::init_player(Handle<Object> 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);

Expand Down