bugfixed first played playlist/track doesn't play

This commit is contained in:
Kingkor Roy Tirtho 2022-03-13 15:08:55 +06:00
parent 932462d773
commit 39a92a56f3
4 changed files with 36 additions and 22 deletions

BIN
assets/warmer.mp3 Normal file

Binary file not shown.

View File

@ -33,6 +33,16 @@ class Player extends HookConsumerWidget {
final AsyncSnapshot<SharedPreferences?> localStorage = final AsyncSnapshot<SharedPreferences?> localStorage =
useFuture(future, initialData: null); 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(() { useEffect(() {
if (localStorage.hasData) { if (localStorage.hasData) {
_volume.value = localStorage.data?.getDouble(LocalStorageKeys.volume) ?? _volume.value = localStorage.data?.getDouble(LocalStorageKeys.volume) ??

View File

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
@ -52,25 +50,28 @@ class PlayerView extends HookConsumerWidget {
body: Column( body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Column( Padding(
children: [ padding: const EdgeInsets.all(10),
Text( child: Column(
currentTrack?.name ?? "Not playing", children: [
overflow: TextOverflow.ellipsis, Text(
style: Theme.of(context).textTheme.headline4?.copyWith( currentTrack?.name ?? "Not playing",
fontWeight: FontWeight.bold, overflow: TextOverflow.ellipsis,
color: paletteColor.titleTextColor, style: Theme.of(context).textTheme.headline4?.copyWith(
), fontWeight: FontWeight.bold,
), color: paletteColor.titleTextColor,
artistsToClickableArtists( ),
currentTrack?.artists ?? [], ),
mainAxisAlignment: MainAxisAlignment.center, artistsToClickableArtists(
textStyle: Theme.of(context).textTheme.headline6!.copyWith( currentTrack?.artists ?? [],
fontWeight: FontWeight.bold, mainAxisAlignment: MainAxisAlignment.center,
color: paletteColor.bodyTextColor, textStyle: Theme.of(context).textTheme.headline6!.copyWith(
), fontWeight: FontWeight.bold,
), color: paletteColor.bodyTextColor,
], ),
),
],
),
), ),
HookBuilder(builder: (context) { HookBuilder(builder: (context) {
final ticker = useSingleTickerProvider(); final ticker = useSingleTickerProvider();

View File

@ -224,7 +224,10 @@ class Playback extends ChangeNotifier {
final ytTrack = await toYoutubeTrack(youtube, track); final ytTrack = await toYoutubeTrack(youtube, track);
if (setTrackUriById(track.id!, ytTrack.uri!)) { if (setTrackUriById(track.id!, ytTrack.uri!)) {
await player await player
.setAudioSource(AudioSource.uri(Uri.parse(ytTrack.uri!))) .setAudioSource(
AudioSource.uri(Uri.parse(ytTrack.uri!)),
preload: true,
)
.then((value) { .then((value) {
_currentTrack = track; _currentTrack = track;
notifyListeners(); notifyListeners();