Skip to content

Commit

Permalink
imp - Stop() waits until playback stops
Browse files Browse the repository at this point in the history
---

We've used a spin wait mechanism to wait until we declare the playback as stopped.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed May 30, 2024
1 parent b100c29 commit 02eb3e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion BassBoom.Basolia/Playback/PlaybackState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public enum PlaybackState
/// <summary>
/// Music has been paused by the user or by the call to the <see cref="PlaybackTools.Pause"/> function
/// </summary>
Paused
Paused,
/// <summary>
/// Music is stopping
/// </summary>
Stopping,
}
}
5 changes: 3 additions & 2 deletions BassBoom.Basolia/Playback/PlaybackTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static void Play()
FeedRadio();
}
} while (err == (int)mpg123_errors.MPG123_OK && Playing);
if (Playing)
if (Playing || state == PlaybackState.Stopping)
state = PlaybackState.Stopped;
}
}
Expand Down Expand Up @@ -187,7 +187,8 @@ public static void Stop()
throw new BasoliaException("Can't stop a file that's not open", mpg123_errors.MPG123_BAD_FILE);

// Stop the music and seek to the beginning
state = PlaybackState.Stopped;
state = state == PlaybackState.Playing ? PlaybackState.Stopping : PlaybackState.Stopped;
SpinWait.SpinUntil(() => state == PlaybackState.Stopped);
if (!FileTools.IsRadioStation)
PlaybackPositioningTools.SeekToTheBeginning();
}
Expand Down

0 comments on commit 02eb3e3

Please sign in to comment.