From 90f6ffbdb7c7cc07cb02b69fcfb3a3844f0180b7 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Fri, 14 Mar 2014 11:47:26 +0100 Subject: piano: Request track length The returned length is used as first length estimate before enough audio data arrives to show the real length and for the eventcmd API. See #427 and #64. --- src/libpiano/piano.h | 1 + src/libpiano/request.c | 2 ++ src/libpiano/response.c | 2 ++ src/main.c | 4 ++-- 4 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h index d8b84ce..e97649e 100644 --- a/src/libpiano/piano.h +++ b/src/libpiano/piano.h @@ -95,6 +95,7 @@ typedef struct PianoSong { char *detailUrl; char *trackToken; float fileGain; + unsigned int length; /* song length in seconds */ PianoSongRating_t rating; PianoAudioFormat_t audioFormat; } PianoSong_t; diff --git a/src/libpiano/request.c b/src/libpiano/request.c index 82bf350..6d0c8e5 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -133,6 +133,8 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, json_object_object_add (j, "stationToken", json_object_new_string (reqData->station->id)); + json_object_object_add (j, "includeTrackLength", + json_object_new_boolean (true)); method = "station.getPlaylist"; break; diff --git a/src/libpiano/response.c b/src/libpiano/response.c index 53d22c1..fefa610 100644 --- a/src/libpiano/response.c +++ b/src/libpiano/response.c @@ -278,6 +278,8 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) { song->detailUrl = PianoJsonStrdup (s, "songDetailUrl"); song->fileGain = json_object_get_double ( json_object_object_get (s, "trackGain")); + song->length = json_object_get_int ( + json_object_object_get (s, "trackLength")); switch (json_object_get_int (json_object_object_get (s, "songRating"))) { case 1: diff --git a/src/main.c b/src/main.c index ba46770..9fa94eb 100644 --- a/src/main.c +++ b/src/main.c @@ -268,6 +268,7 @@ static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) { app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume); app->player.audioFormat = app->playlist->audioFormat; app->player.settings = &app->settings; + app->player.songDuration = app->playlist->length * 1000; pthread_mutex_init (&app->player.pauseMutex, NULL); pthread_cond_init (&app->player.pauseCond, NULL); @@ -388,8 +389,7 @@ static void BarMainLoop (BarApp_t *app) { BarMainHandleUserInput (app); /* show time */ - if (app->player.mode >= PLAYER_SAMPLESIZE_INITIALIZED && - app->player.mode < PLAYER_FINISHED_PLAYBACK) { + if (app->player.mode < PLAYER_FINISHED_PLAYBACK) { BarMainPrintTime (app); } } -- cgit v1.2.3