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, : context.l10n.shuffle_playlist,
icon: const Icon(SpotubeIcons.shuffle), icon: const Icon(SpotubeIcons.shuffle),
style: shuffled ? activeButtonStyle : buttonStyle, style: shuffled ? activeButtonStyle : buttonStyle,
onPressed: playlist.isFetching onPressed: playlist.isFetching == true || buffering
? null ? null
: () { : () {
if (shuffled) { if (shuffled) {
@ -212,7 +212,9 @@ class PlayerControls extends HookConsumerWidget {
tooltip: context.l10n.previous_track, tooltip: context.l10n.previous_track,
icon: const Icon(SpotubeIcons.skipBack), icon: const Icon(SpotubeIcons.skipBack),
style: buttonStyle, style: buttonStyle,
onPressed: playlistNotifier.previous, onPressed: playlist.isFetching == true || buffering
? null
: playlistNotifier.previous,
), ),
IconButton( IconButton(
tooltip: playing tooltip: playing
@ -242,7 +244,9 @@ class PlayerControls extends HookConsumerWidget {
tooltip: context.l10n.next_track, tooltip: context.l10n.next_track,
icon: const Icon(SpotubeIcons.skipForward), icon: const Icon(SpotubeIcons.skipForward),
style: buttonStyle, style: buttonStyle,
onPressed: playlistNotifier.next, onPressed: playlist.isFetching == true || buffering
? null
: playlistNotifier.next,
), ),
StreamBuilder<PlaybackLoopMode>( StreamBuilder<PlaybackLoopMode>(
stream: audioPlayer.loopModeStream, stream: audioPlayer.loopModeStream,
@ -251,24 +255,34 @@ class PlayerControls extends HookConsumerWidget {
return IconButton( return IconButton(
tooltip: loopMode == PlaybackLoopMode.one tooltip: loopMode == PlaybackLoopMode.one
? context.l10n.loop_track ? context.l10n.loop_track
: context.l10n.repeat_playlist, : loopMode == PlaybackLoopMode.all
? context.l10n.repeat_playlist
: null,
icon: Icon( icon: Icon(
loopMode == PlaybackLoopMode.one loopMode == PlaybackLoopMode.one
? SpotubeIcons.repeatOne ? SpotubeIcons.repeatOne
: SpotubeIcons.repeat, : SpotubeIcons.repeat,
), ),
style: loopMode == PlaybackLoopMode.one style: loopMode == PlaybackLoopMode.one ||
loopMode == PlaybackLoopMode.all
? activeButtonStyle ? activeButtonStyle
: buttonStyle, : buttonStyle,
onPressed: playlist.isFetching onPressed: playlist.isFetching == true || buffering
? null ? null
: () { : () async {
if (loopMode == PlaybackLoopMode.one) { switch (await audioPlayer.loopMode) {
audioPlayer case PlaybackLoopMode.all:
.setLoopMode(PlaybackLoopMode.all);
} else {
audioPlayer audioPlayer
.setLoopMode(PlaybackLoopMode.one); .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, enableApplicationParameters: false,
), ),
FileHandler(await getLogsPath(), printLogs: false), FileHandler(await getLogsPath(), printLogs: false),
SnackbarHandler(const Duration(seconds: 3)),
], ],
), ),
releaseConfig: CatcherOptions(SilentReportMode(), [ releaseConfig: CatcherOptions(
SilentReportMode(),
[
if (arguments["verbose"] ?? false) if (arguments["verbose"] ?? false)
ConsoleHandler( ConsoleHandler(
enableDeviceParameters: false, enableDeviceParameters: false,
enableApplicationParameters: false, enableApplicationParameters: false,
), ),
ToastHandler(),
FileHandler( FileHandler(
await getLogsPath(), await getLogsPath(),
printLogs: false, printLogs: false,
), ),
]), SnackbarHandler(const Duration(seconds: 3)),
],
),
runAppFunction: () { runAppFunction: () {
runApp( runApp(
DevicePreview( DevicePreview(

View File

@ -120,6 +120,9 @@ class SpotubeTrack extends Track {
ytVideo = await PipedSpotube.client.streams(matchedCachedTrack.youtubeId); ytVideo = await PipedSpotube.client.streams(matchedCachedTrack.youtubeId);
} else { } else {
siblings = await fetchSiblings(track); 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); ytVideo = await PipedSpotube.client.streams(siblings.first.id);
await MatchedTrack.box.put( await MatchedTrack.box.put(

View File

@ -1,5 +1,5 @@
import 'package:catcher/catcher.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotify/spotify.dart'; import 'package:spotify/spotify.dart';
import 'package:spotube/models/local_track.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 /// This method must be called after any playback operation as
/// it can increase the latency /// it can increase the latency
Future<void> storeTrack(Track track, SpotubeTrack spotubeTrack) async { Future<void> storeTrack(Track track, SpotubeTrack spotubeTrack) async {
try {
if (track is! SpotubeTrack) { if (track is! SpotubeTrack) {
await supabase await supabase.insertTrack(
.insertTrack(
MatchedTrack( MatchedTrack(
youtubeId: spotubeTrack.ytTrack.id, youtubeId: spotubeTrack.ytTrack.id,
spotifyId: spotubeTrack.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 { }) async {
tracks = blacklist.filter(tracks).toList() as List<Track>; tracks = blacklist.filter(tracks).toList() as List<Track>;
final addableTrack = await SpotubeTrack.fetchFromTrack( final addableTrack = await SpotubeTrack.fetchFromTrack(
tracks.elementAt(initialIndex), tracks.elementAtOrNull(initialIndex) ?? tracks.first,
preferences, preferences,
); );