Playback track search retry-able now

Search page not rendering fix
This commit is contained in:
Kingkor Roy Tirtho 2022-07-06 00:59:33 +06:00
parent e2bba4ac94
commit c51a9a4c28
6 changed files with 171 additions and 141 deletions

View File

@ -67,7 +67,7 @@ class PlayerView extends HookConsumerWidget {
), ),
child: BackdropFilter( child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 15, sigmaY: 15), filter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: Container( child: Material(
color: paletteColor.color.withOpacity(.5), color: paletteColor.color.withOpacity(.5),
child: SafeArea( child: SafeArea(
child: Column( child: Column(

View File

@ -37,8 +37,8 @@ class Search extends HookConsumerWidget {
} }
final searchSnapshot = ref.watch(searchQuery(searchTerm)); final searchSnapshot = ref.watch(searchQuery(searchTerm));
return SafeArea( return Expanded(
child: Expanded( child: SafeArea(
child: Container( child: Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor,
child: Column( child: Column(

View File

@ -177,6 +177,8 @@ class TrackTile extends HookConsumerWidget {
: Colors.transparent, : Colors.transparent,
borderRadius: BorderRadius.circular(isActive ? 10 : 0), borderRadius: BorderRadius.circular(isActive ? 10 : 0),
), ),
child: Material(
type: MaterialType.transparency,
child: Row( child: Row(
children: [ children: [
SizedBox( SizedBox(
@ -211,7 +213,8 @@ class TrackTile extends HookConsumerWidget {
), ),
IconButton( IconButton(
icon: Icon( icon: Icon(
playback.track?.id != null && playback.track?.id == track.value.id playback.track?.id != null &&
playback.track?.id == track.value.id
? Icons.pause_circle_rounded ? Icons.pause_circle_rounded
: Icons.play_circle_rounded, : Icons.play_circle_rounded,
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
@ -323,6 +326,7 @@ class TrackTile extends HookConsumerWidget {
), ),
], ],
), ),
),
); );
} }
} }

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:async/async.dart';
import 'package:audio_service/audio_service.dart'; import 'package:audio_service/audio_service.dart';
import 'package:audioplayers/audioplayers.dart'; import 'package:audioplayers/audioplayers.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -227,6 +228,27 @@ class Playback extends PersistedChangeNotifier {
player.dispose(); player.dispose();
} }
Future<T> retryingOperation<T>(
Future<T> Function() inner, {
Duration? timeout,
}) async {
T result;
try {
final operation = CancelableOperation.fromFuture(inner());
result = await operation.value;
await Future.delayed(timeout ?? const Duration(seconds: 5), () async {
if (!operation.isCompleted) {
operation.cancel();
result = await inner();
}
});
return result;
} catch (e) {
result = await inner();
return result;
}
}
// playlist & track list methods // playlist & track list methods
Future<SpotubeTrack> toSpotubeTrack(Track track) async { Future<SpotubeTrack> toSpotubeTrack(Track track) async {
final format = preferences.ytSearchFormat; final format = preferences.ytSearchFormat;
@ -260,7 +282,8 @@ class Playback extends PersistedChangeNotifier {
); );
ytVideo = VideoFromCacheTrackExtension.fromCacheTrack(cachedTrack); ytVideo = VideoFromCacheTrackExtension.fromCacheTrack(cachedTrack);
} else { } else {
VideoSearchList videos = await youtube.search.search(queryString); VideoSearchList videos =
await retryingOperation(() => youtube.search.search(queryString));
if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) { if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) {
List<Map> ratedRankedVideos = videos List<Map> ratedRankedVideos = videos
.map((video) { .map((video) {
@ -310,7 +333,9 @@ class Playback extends PersistedChangeNotifier {
} }
} }
final trackManifest = await youtube.videos.streams.getManifest(ytVideo.id); StreamManifest trackManifest = await retryingOperation(
() => youtube.videos.streams.getManifest(ytVideo.id),
);
_logger.v( _logger.v(
"[YouTube Matched Track] ${ytVideo.title} | ${ytVideo.author} - ${ytVideo.url}", "[YouTube Matched Track] ${ytVideo.title} | ${ytVideo.author} - ${ytVideo.url}",

View File

@ -37,7 +37,7 @@ packages:
source: hosted source: hosted
version: "2.3.1" version: "2.3.1"
async: async:
dependency: transitive dependency: "direct main"
description: description:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

View File

@ -64,6 +64,7 @@ dependencies:
dbus: ^0.7.3 dbus: ^0.7.3
audioplayers: ^1.0.1 audioplayers: ^1.0.1
resizable_widget: ^1.0.5 resizable_widget: ^1.0.5
async: ^2.8.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: