Skip to content

Commit

Permalink
Toggle Station correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
korli committed Dec 19, 2023
1 parent 1ece894 commit 3f8a3db
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,17 @@ MainWindow::_Invoke(StationListViewItem* stationItem)
{
if (stationItem == NULL)
return;
bool wasActive = false;
if (!fAllowParallelPlayback) {
while (!fActiveStations.IsEmpty())
_TogglePlay(fActiveStations.LastItem());
if (fActiveStations.HasItem(stationItem))
return;
while (!fActiveStations.IsEmpty()) {
StationListViewItem* item = fActiveStations.LastItem();
if (item == stationItem)
wasActive = true;
_TogglePlay(item);
}
}
_TogglePlay(stationItem);
if (!wasActive)
_TogglePlay(stationItem);
}


Expand All @@ -416,18 +420,17 @@ MainWindow::_TogglePlay(StationListViewItem* stationItem)
{
status_t status = B_ERROR;

StreamPlayer* player
= new StreamPlayer(stationItem->GetStation(), this);
if (player != NULL) {
status = player->InitCheck();
if (status == B_OK)
status = player->Play();
StreamPlayer* player = stationItem->Player();
if (player == NULL)
player = new StreamPlayer(stationItem->GetStation(), this);
status = player->InitCheck();
if (status == B_OK) {
status = player->Play();
} else {
status = B_NO_MEMORY;
}

if (status == B_OK) {
stationItem->SetPlayer(player);
stationItem->StateChanged(StreamPlayer::Playing);
fStationList->SelectItem(stationItem);
BString success;
Expand All @@ -446,6 +449,7 @@ MainWindow::_TogglePlay(StationListViewItem* stationItem)
strerror(status));
fStatusBar->SetText(error);
}
stationItem->SetPlayer(player);

break;
}
Expand Down

0 comments on commit 3f8a3db

Please sign in to comment.