From 0ec2df77a72edde7b65a4ac8e7ffff4470120a51 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 14 Apr 2016 16:21:34 +0200 Subject: Fix songfinish event when changing stations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The event did not contain any song data (title, artist, …), because the playlist was destroyed by the ui command. Now the actual station switch is deferred by introducing nextStation and letting the main loop handle it. Fixes issue #584. --- src/main.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index c0388e2..a85949a 100644 --- a/src/main.c +++ b/src/main.c @@ -177,21 +177,18 @@ static bool BarMainGetStations (BarApp_t *app) { static void BarMainGetInitialStation (BarApp_t *app) { /* try to get autostart station */ if (app->settings.autostartStation != NULL) { - app->curStation = PianoFindStationById (app->ph.stations, + app->nextStation = PianoFindStationById (app->ph.stations, app->settings.autostartStation); - if (app->curStation == NULL) { + if (app->nextStation == NULL) { BarUiMsg (&app->settings, MSG_ERR, "Error: Autostart station not found.\n"); } } /* no autostart? ask the user */ - if (app->curStation == NULL) { - app->curStation = BarUiSelectStation (app, app->ph.stations, + if (app->nextStation == NULL) { + app->nextStation = BarUiSelectStation (app, app->ph.stations, "Select station: ", NULL, app->settings.autoselect); } - if (app->curStation != NULL) { - BarUiPrintStation (&app->settings, app->curStation); - } } /* wait for user input @@ -211,20 +208,21 @@ static void BarMainGetPlaylist (BarApp_t *app) { PianoReturn_t pRet; CURLcode wRet; PianoRequestDataGetPlaylist_t reqData; - reqData.station = app->curStation; + reqData.station = app->nextStation; reqData.quality = app->settings.audioQuality; BarUiMsg (&app->settings, MSG_INFO, "Receiving new playlist... "); if (!BarUiPianoCall (app, PIANO_REQUEST_GET_PLAYLIST, &reqData, &pRet, &wRet)) { - app->curStation = NULL; + app->nextStation = NULL; } else { app->playlist = reqData.retPlaylist; if (app->playlist == NULL) { BarUiMsg (&app->settings, MSG_INFO, "No tracks left.\n"); - app->curStation = NULL; + app->nextStation = NULL; } } + app->curStation = app->nextStation; BarUiStartEventCmd (&app->settings, "stationfetchplaylist", app->curStation, app->playlist, &app->player, app->ph.stations, pRet, wRet); @@ -297,10 +295,10 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) { ++app->playerErrors; if (app->playerErrors >= app->settings.maxPlayerErrors) { /* don't continue playback if thread reports too many error */ - app->curStation = NULL; + app->nextStation = NULL; } } else { - app->curStation = NULL; + app->nextStation = NULL; } memset (&app->player, 0, sizeof (app->player)); @@ -363,8 +361,7 @@ static void BarMainLoop (BarApp_t *app) { /* check whether player finished playing and start playing new * song */ - if (app->player.mode == PLAYER_DEAD && app->curStation != NULL && - !app->doQuit) { + if (app->player.mode == PLAYER_DEAD) { /* what's next? */ if (app->playlist != NULL) { PianoSong_t *histsong = app->playlist; @@ -372,7 +369,10 @@ static void BarMainLoop (BarApp_t *app) { histsong->head.next = NULL; BarUiHistoryPrepend (app, histsong); } - if (app->playlist == NULL) { + if (app->playlist == NULL && app->nextStation != NULL && !app->doQuit) { + if (app->nextStation != app->curStation) { + BarUiPrintStation (&app->settings, app->nextStation); + } BarMainGetPlaylist (app); } /* song ready to play */ -- cgit v1.2.3