feat: repeat button all 3 mode and disable player controls when track is fetching

This commit is contained in:
Kingkor Roy Tirtho 2023-06-04 16:34:37 +06:00
parent e3d8239b9f
commit 14183781dd
5 changed files with 60 additions and 34 deletions

View File

@ -197,7 +197,7 @@ class PlayerControls extends HookConsumerWidget {
: context.l10n.shuffle_playlist,
icon: const Icon(SpotubeIcons.shuffle),
style: shuffled ? activeButtonStyle : buttonStyle,
onPressed: playlist.isFetching
onPressed: playlist.isFetching == true || buffering
? null
: () {
if (shuffled) {
@ -212,7 +212,9 @@ class PlayerControls extends HookConsumerWidget {
tooltip: context.l10n.previous_track,
icon: const Icon(SpotubeIcons.skipBack),
style: buttonStyle,
onPressed: playlistNotifier.previous,
onPressed: playlist.isFetching == true || buffering
? null
: playlistNotifier.previous,
),
IconButton(
tooltip: playing
@ -242,7 +244,9 @@ class PlayerControls extends HookConsumerWidget {
tooltip: context.l10n.next_track,
icon: const Icon(SpotubeIcons.skipForward),
style: buttonStyle,
onPressed: playlistNotifier.next,
onPressed: playlist.isFetching == true || buffering
? null
: playlistNotifier.next,
),
StreamBuilder<PlaybackLoopMode>(
stream: audioPlayer.loopModeStream,
@ -251,24 +255,34 @@ class PlayerControls extends HookConsumerWidget {
return IconButton(
tooltip: loopMode == PlaybackLoopMode.one
? context.l10n.loop_track
: context.l10n.repeat_playlist,
: loopMode == PlaybackLoopMode.all
? context.l10n.repeat_playlist
: null,
icon: Icon(
loopMode == PlaybackLoopMode.one
? SpotubeIcons.repeatOne
: SpotubeIcons.repeat,
),
style: loopMode == PlaybackLoopMode.one
style: loopMode == PlaybackLoopMode.one ||
loopMode == PlaybackLoopMode.all
? activeButtonStyle
: buttonStyle,
onPressed: playlist.isFetching
onPressed: playlist.isFetching == true || buffering
? null
: () {
if (loopMode == PlaybackLoopMode.one) {
audioPlayer
.setLoopMode(PlaybackLoopMode.all);
} else {
: () async {
switch (await audioPlayer.loopMode) {
case PlaybackLoopMode.all:
audioPlayer
.setLoopMode(PlaybackLoopMode.one);
break;
case PlaybackLoopMode.one:
audioPlayer
.setLoopMode(PlaybackLoopMode.none);
break;
case PlaybackLoopMode.none:
audioPlayer
.setLoopMode(PlaybackLoopMode.all);
break;
}
},
);

View File

@ -119,19 +119,25 @@ Future<void> main(List<String> rawArgs) async {
enableApplicationParameters: false,
),
FileHandler(await getLogsPath(), printLogs: false),
SnackbarHandler(const Duration(seconds: 3)),
],
),
releaseConfig: CatcherOptions(SilentReportMode(), [
releaseConfig: CatcherOptions(
SilentReportMode(),
[
if (arguments["verbose"] ?? false)
ConsoleHandler(
enableDeviceParameters: false,
enableApplicationParameters: false,
),
ToastHandler(),
FileHandler(
await getLogsPath(),
printLogs: false,
),
]),
SnackbarHandler(const Duration(seconds: 3)),
],
),
runAppFunction: () {
runApp(
DevicePreview(

View File

@ -120,6 +120,9 @@ class SpotubeTrack extends Track {
ytVideo = await PipedSpotube.client.streams(matchedCachedTrack.youtubeId);
} else {
siblings = await fetchSiblings(track);
if (siblings.isEmpty) {
throw Exception("Failed to find any results for ${track.name}");
}
ytVideo = await PipedSpotube.client.streams(siblings.first.id);
await MatchedTrack.box.put(

View File

@ -1,5 +1,5 @@
import 'package:catcher/catcher.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/models/local_track.dart';
@ -105,15 +105,18 @@ mixin NextFetcher on StateNotifier<ProxyPlaylist> {
/// This method must be called after any playback operation as
/// it can increase the latency
Future<void> storeTrack(Track track, SpotubeTrack spotubeTrack) async {
try {
if (track is! SpotubeTrack) {
await supabase
.insertTrack(
await supabase.insertTrack(
MatchedTrack(
youtubeId: spotubeTrack.ytTrack.id,
spotifyId: spotubeTrack.id!,
),
)
.catchError(Catcher.reportCheckedError);
);
}
} catch (e, stackTrace) {
debugPrint(e.toString());
debugPrintStack(stackTrace: stackTrace);
}
}
}

View File

@ -218,7 +218,7 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
}) async {
tracks = blacklist.filter(tracks).toList() as List<Track>;
final addableTrack = await SpotubeTrack.fetchFromTrack(
tracks.elementAt(initialIndex),
tracks.elementAtOrNull(initialIndex) ?? tracks.first,
preferences,
);