Skip to content

Commit

Permalink
feat: repeat button all 3 mode and disable player controls when track…
Browse files Browse the repository at this point in the history
… is fetching
  • Loading branch information
KRTirtho committed Jun 4, 2023
1 parent e3d8239 commit 1418378
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 deletions.
40 changes: 27 additions & 13 deletions lib/components/player/player_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
audioPlayer
.setLoopMode(PlaybackLoopMode.one);
: () 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;
}
},
);
Expand Down
26 changes: 16 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [
if (arguments["verbose"] ?? false)
ConsoleHandler(
enableDeviceParameters: false,
enableApplicationParameters: false,
releaseConfig: CatcherOptions(
SilentReportMode(),
[
if (arguments["verbose"] ?? false)
ConsoleHandler(
enableDeviceParameters: false,
enableApplicationParameters: false,
),
ToastHandler(),
FileHandler(
await getLogsPath(),
printLogs: false,
),
FileHandler(
await getLogsPath(),
printLogs: false,
),
]),
SnackbarHandler(const Duration(seconds: 3)),
],
),
runAppFunction: () {
runApp(
DevicePreview(
Expand Down
3 changes: 3 additions & 0 deletions lib/models/spotube_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 13 additions & 10 deletions lib/provider/proxy_playlist/next_fetcher_mixin.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
if (track is! SpotubeTrack) {
await supabase
.insertTrack(
MatchedTrack(
youtubeId: spotubeTrack.ytTrack.id,
spotifyId: spotubeTrack.id!,
),
)
.catchError(Catcher.reportCheckedError);
try {
if (track is! SpotubeTrack) {
await supabase.insertTrack(
MatchedTrack(
youtubeId: spotubeTrack.ytTrack.id,
spotifyId: spotubeTrack.id!,
),
);
}
} catch (e, stackTrace) {
debugPrint(e.toString());
debugPrintStack(stackTrace: stackTrace);
}
}
}
2 changes: 1 addition & 1 deletion lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down

0 comments on commit 1418378

Please sign in to comment.