mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
Slow Playback track play execution fixed
Sidebar abnormal ProgressBar size fix Player volume slider stays at zero on fresh start fix
This commit is contained in:
parent
acc939c581
commit
07f70af96d
@ -8,6 +8,7 @@ import 'package:spotube/helpers/image-to-url-string.dart';
|
|||||||
import 'package:spotube/hooks/useBreakpointValue.dart';
|
import 'package:spotube/hooks/useBreakpointValue.dart';
|
||||||
import 'package:spotube/hooks/useBreakpoints.dart';
|
import 'package:spotube/hooks/useBreakpoints.dart';
|
||||||
import 'package:spotube/models/sideBarTiles.dart';
|
import 'package:spotube/models/sideBarTiles.dart';
|
||||||
|
import 'package:spotube/provider/Auth.dart';
|
||||||
import 'package:spotube/provider/SpotifyRequests.dart';
|
import 'package:spotube/provider/SpotifyRequests.dart';
|
||||||
|
|
||||||
class Sidebar extends HookConsumerWidget {
|
class Sidebar extends HookConsumerWidget {
|
||||||
@ -38,6 +39,7 @@ class Sidebar extends HookConsumerWidget {
|
|||||||
if (breakpoints.isSm) return Container();
|
if (breakpoints.isSm) return Container();
|
||||||
final extended = useState(false);
|
final extended = useState(false);
|
||||||
final meSnapshot = ref.watch(currentUserQuery);
|
final meSnapshot = ref.watch(currentUserQuery);
|
||||||
|
final auth = ref.watch(authProvider);
|
||||||
|
|
||||||
final int titleBarDragMaxWidth = useBreakpointValue(
|
final int titleBarDragMaxWidth = useBreakpointValue(
|
||||||
md: 80,
|
md: 80,
|
||||||
@ -104,16 +106,23 @@ class Sidebar extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: titleBarDragMaxWidth.toDouble(),
|
width: titleBarDragMaxWidth.toDouble(),
|
||||||
child: meSnapshot.when(
|
child: Builder(
|
||||||
data: (data) {
|
builder: (context) {
|
||||||
final avatarImg = imageToUrlString(data.images,
|
final data = meSnapshot.asData?.value;
|
||||||
index: (data.images?.length ?? 1) - 1);
|
|
||||||
|
final avatarImg = imageToUrlString(data?.images,
|
||||||
|
index: (data?.images?.length ?? 1) - 1);
|
||||||
if (extended.value) {
|
if (extended.value) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
|
if (auth.isLoggedIn && data == null)
|
||||||
|
const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
)
|
||||||
|
else if (data != null)
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
@ -146,8 +155,6 @@ class Sidebar extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: (e, _) => Text("Error $e"),
|
|
||||||
loading: () => const CircularProgressIndicator(),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -104,9 +104,14 @@ class Player extends HookConsumerWidget {
|
|||||||
height: 20,
|
height: 20,
|
||||||
constraints: const BoxConstraints(maxWidth: 200),
|
constraints: const BoxConstraints(maxWidth: 200),
|
||||||
child: HookBuilder(builder: (context) {
|
child: HookBuilder(builder: (context) {
|
||||||
final volume = useState(
|
final volume = useState(playback.volume);
|
||||||
useMemoized(() => playback.volume, []),
|
|
||||||
);
|
useEffect(() {
|
||||||
|
if (volume.value != playback.volume) {
|
||||||
|
volume.value = playback.volume;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}, [playback.volume]);
|
||||||
return Slider.adaptive(
|
return Slider.adaptive(
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 1,
|
max: 1,
|
||||||
|
@ -2,7 +2,6 @@ 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';
|
||||||
@ -123,6 +122,7 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> playPlaylist(CurrentPlaylist playlist, [int index = 0]) async {
|
Future<void> playPlaylist(CurrentPlaylist playlist, [int index = 0]) async {
|
||||||
|
try {
|
||||||
if (index < 0 || index > playlist.tracks.length - 1) return;
|
if (index < 0 || index > playlist.tracks.length - 1) return;
|
||||||
this.playlist = playlist;
|
this.playlist = playlist;
|
||||||
final played = this.playlist!.tracks[index];
|
final played = this.playlist!.tracks[index];
|
||||||
@ -136,6 +136,9 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
this.playlist!.tracks[i] = track!;
|
this.playlist!.tracks[i] = track!;
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
_logger.e("[playPlaylist] $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// player methods
|
// player methods
|
||||||
@ -228,25 +231,20 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
player.dispose();
|
player.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<T> retryingOperation<T>(
|
Future<T> raceMultiple<T>(
|
||||||
Future<T> Function() inner, {
|
Future<T> Function() inner, {
|
||||||
Duration? timeout,
|
Duration timeout = const Duration(milliseconds: 2500),
|
||||||
|
int retryCount = 4,
|
||||||
}) async {
|
}) async {
|
||||||
T result;
|
return Future.any(
|
||||||
try {
|
List.generate(retryCount, (i) {
|
||||||
final operation = CancelableOperation.fromFuture(inner());
|
if (i == 0) return inner();
|
||||||
result = await operation.value;
|
return Future.delayed(
|
||||||
await Future.delayed(timeout ?? const Duration(seconds: 5), () async {
|
Duration(milliseconds: timeout.inMilliseconds * i),
|
||||||
if (!operation.isCompleted) {
|
inner,
|
||||||
operation.cancel();
|
);
|
||||||
result = await inner();
|
}),
|
||||||
}
|
);
|
||||||
});
|
|
||||||
return result;
|
|
||||||
} catch (e) {
|
|
||||||
result = await inner();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// playlist & track list methods
|
// playlist & track list methods
|
||||||
@ -283,7 +281,7 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
ytVideo = VideoFromCacheTrackExtension.fromCacheTrack(cachedTrack);
|
ytVideo = VideoFromCacheTrackExtension.fromCacheTrack(cachedTrack);
|
||||||
} else {
|
} else {
|
||||||
VideoSearchList videos =
|
VideoSearchList videos =
|
||||||
await retryingOperation(() => youtube.search.search(queryString));
|
await raceMultiple(() => youtube.search.search(queryString));
|
||||||
if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) {
|
if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) {
|
||||||
List<Map> ratedRankedVideos = videos
|
List<Map> ratedRankedVideos = videos
|
||||||
.map((video) {
|
.map((video) {
|
||||||
@ -333,7 +331,7 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamManifest trackManifest = await retryingOperation(
|
StreamManifest trackManifest = await raceMultiple(
|
||||||
() => youtube.videos.streams.getManifest(ytVideo.id),
|
() => youtube.videos.streams.getManifest(ytVideo.id),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user