From 39a92a56f3bbcca449b4587f9be995d15fc3912c Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 13 Mar 2022 15:08:55 +0600 Subject: [PATCH] bugfixed first played playlist/track doesn't play --- assets/warmer.mp3 | Bin 0 -> 8777 bytes lib/components/Player/Player.dart | 10 ++++++ lib/components/Player/PlayerView.dart | 43 +++++++++++++------------- lib/provider/Playback.dart | 5 ++- 4 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 assets/warmer.mp3 diff --git a/assets/warmer.mp3 b/assets/warmer.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..638976b2de9df3f45c33c21261a4b6f78109b89d GIT binary patch literal 8777 zcmeIvu@Qm*5Jb^+AkZ!>f(8i8q$f&ntbsxZ=!yXCV8fsM3vYv+*>|0vBg3BCmgJdC zYcjs)7Xo1$RP+N%36`}=Nzd~&x zI#-AmX#EPch3H%%TA=kS)E1(1g=m4+uTWcv&K05sTE9YVAv#xx7HItnwT0+hAzGmI JE7TUE^B)!Ij#2;s literal 0 HcmV?d00001 diff --git a/lib/components/Player/Player.dart b/lib/components/Player/Player.dart index ff04d3b0..d179afb4 100644 --- a/lib/components/Player/Player.dart +++ b/lib/components/Player/Player.dart @@ -33,6 +33,16 @@ class Player extends HookConsumerWidget { final AsyncSnapshot localStorage = useFuture(future, initialData: null); + useEffect(() { + /// warm up the audio player before playing actual audio + /// It's for resolving unresolved issue related to just_audio's + /// [disposeAllPlayers] method which is throwing + /// [UnimplementedException] in the [PlatformInterface] + /// implementation + player.setAsset("assets/warmer.mp3"); + return null; + }, []); + useEffect(() { if (localStorage.hasData) { _volume.value = localStorage.data?.getDouble(LocalStorageKeys.volume) ?? diff --git a/lib/components/Player/PlayerView.dart b/lib/components/Player/PlayerView.dart index c036bcdb..c6281970 100644 --- a/lib/components/Player/PlayerView.dart +++ b/lib/components/Player/PlayerView.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -52,25 +50,28 @@ class PlayerView extends HookConsumerWidget { body: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Column( - children: [ - Text( - currentTrack?.name ?? "Not playing", - overflow: TextOverflow.ellipsis, - style: Theme.of(context).textTheme.headline4?.copyWith( - fontWeight: FontWeight.bold, - color: paletteColor.titleTextColor, - ), - ), - artistsToClickableArtists( - currentTrack?.artists ?? [], - mainAxisAlignment: MainAxisAlignment.center, - textStyle: Theme.of(context).textTheme.headline6!.copyWith( - fontWeight: FontWeight.bold, - color: paletteColor.bodyTextColor, - ), - ), - ], + Padding( + padding: const EdgeInsets.all(10), + child: Column( + children: [ + Text( + currentTrack?.name ?? "Not playing", + overflow: TextOverflow.ellipsis, + style: Theme.of(context).textTheme.headline4?.copyWith( + fontWeight: FontWeight.bold, + color: paletteColor.titleTextColor, + ), + ), + artistsToClickableArtists( + currentTrack?.artists ?? [], + mainAxisAlignment: MainAxisAlignment.center, + textStyle: Theme.of(context).textTheme.headline6!.copyWith( + fontWeight: FontWeight.bold, + color: paletteColor.bodyTextColor, + ), + ), + ], + ), ), HookBuilder(builder: (context) { final ticker = useSingleTickerProvider(); diff --git a/lib/provider/Playback.dart b/lib/provider/Playback.dart index a94fc842..4d59d981 100644 --- a/lib/provider/Playback.dart +++ b/lib/provider/Playback.dart @@ -224,7 +224,10 @@ class Playback extends ChangeNotifier { final ytTrack = await toYoutubeTrack(youtube, track); if (setTrackUriById(track.id!, ytTrack.uri!)) { await player - .setAudioSource(AudioSource.uri(Uri.parse(ytTrack.uri!))) + .setAudioSource( + AudioSource.uri(Uri.parse(ytTrack.uri!)), + preload: true, + ) .then((value) { _currentTrack = track; notifyListeners();