[podcast] Stop Audio Playback on Windows and Linux (#84)

On Windows and Linux it could happen that the audio playback for a
podcast wasn't stopped when the item details view for a podcast item was
closed.

This commit "fixes" the problem, by pausing the audio player, before the
widget is disposed.

This commit also fixes the condition when the background audio services
should be initialized in the `main.dart` file. Instead of the macOS
check, we checked for iOS twice.
This commit is contained in:
Rico Berger
2023-11-29 21:06:06 +01:00
committed by GitHub
parent 5a8d6b34c1
commit a58c93be8a
2 changed files with 2 additions and 1 deletions

View File

@@ -57,7 +57,7 @@ void main() async {
/// We can not initialize the [just_audio_background] package on Windows and
/// Linux, because then the returned duration in the `_player.durationStream`
/// isn't working correctly in the [ItemAudioPlayer] widget.
if (kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isIOS) {
if (kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS) {
await JustAudioBackground.init(
androidNotificationChannelId: 'com.ryanheise.bg_demo.channel.audio',
androidNotificationChannelName: 'Audio playback',

View File

@@ -65,6 +65,7 @@ class _ItemAudioPlayerState extends State<ItemAudioPlayer> {
@override
void dispose() {
_player.pause();
_player.dispose();
super.dispose();
}