summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 5050b38..3e7ac54 100644
--- a/src/main.c
+++ b/src/main.c
@@ -183,7 +183,7 @@ static void BarMainGetPlaylist (BarApp_t *app) {
/* start new player thread
*/
-static void BarMainStartPlayback (BarApp_t *app) {
+static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
BarUiPrintSong (&app->settings, app->playlist, app->curStation->isQuickMix ?
PianoFindStationById (app->ph.stations,
app->playlist->stationId) : NULL);
@@ -216,24 +216,26 @@ static void BarMainStartPlayback (BarApp_t *app) {
* thread has been started */
app->player.mode = PLAYER_STARTING;
/* start player */
- pthread_create (&app->player.thread, NULL, BarPlayerThread,
+ pthread_create (playerThread, NULL, BarPlayerThread,
&app->player);
}
}
/* player is done, clean up
*/
-static void BarMainPlayerCleanup (BarApp_t *app) {
+static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) {
+ void *threadRet;
+
BarUiStartEventCmd (&app->settings, "songfinish", app->curStation,
app->playlist, &app->player, app->ph.stations, PIANO_RET_OK,
WAITRESS_RET_OK);
/* FIXME: pthread_join blocks everything if network connection
* is hung up e.g. */
- pthread_join (app->player.thread, NULL);
+ pthread_join (*playerThread, &threadRet);
/* don't continue playback if thread reports error */
- if (app->player.ret != PLAYER_RET_OK) {
+ if (threadRet != (void *) PLAYER_RET_OK) {
app->curStation = NULL;
}
@@ -263,6 +265,8 @@ static void BarMainPrintTime (BarApp_t *app) {
/* main loop
*/
static void BarMainLoop (BarApp_t *app) {
+ pthread_t playerThread;
+
BarMainGetLoginCredentials (&app->settings, &app->input);
BarMainLoadProxy (&app->settings, &app->waith);
@@ -284,7 +288,7 @@ static void BarMainLoop (BarApp_t *app) {
while (!app->doQuit) {
/* song finished playing, clean up things/scrobble song */
if (app->player.mode == PLAYER_FINISHED_PLAYBACK) {
- BarMainPlayerCleanup (app);
+ BarMainPlayerCleanup (app, &playerThread);
}
/* check whether player finished playing and start playing new
@@ -301,7 +305,7 @@ static void BarMainLoop (BarApp_t *app) {
}
/* song ready to play */
if (app->playlist != NULL) {
- BarMainStartPlayback (app);
+ BarMainStartPlayback (app, &playerThread);
}
}
@@ -315,7 +319,7 @@ static void BarMainLoop (BarApp_t *app) {
}
if (app->player.mode != PLAYER_FREED) {
- BarMainPlayerCleanup (app);
+ pthread_join (playerThread, NULL);
}
}