fix buttons that require navigation in track menu

wakelock when lyrics screen open
This commit is contained in:
Pato05 2024-04-27 01:25:33 +02:00
parent 36f8666906
commit 2e67b50332
No known key found for this signature in database
GPG Key ID: F53CA394104BA0CB
7 changed files with 1857 additions and 1856 deletions

View File

@ -143,6 +143,7 @@ class AudioPlayerTask extends BaseAudioHandler {
JustAudioMediaKit.ensureInitialized();
JustAudioMediaKit.title = 'Freezer';
JustAudioMediaKit.protocolWhitelist = const ['http'];
JustAudioMediaKit.prefetchPlaylist = true;
//JustAudioMediaKit.bufferSize = 128;
_deezerAPI = initArgs.deezerAPI;
@ -366,23 +367,6 @@ class AudioPlayerTask extends BaseAudioHandler {
return Future.value();
}
// unused.
@override
Future<void> seekForward(bool begin) => Future.value();
Future<void> seekBackward(bool begin) async {
// (un)favourite action
if (cache.libraryTracks.contains(currentMediaItem.id)) {
cache.libraryTracks.remove(currentMediaItem.id);
_broadcastState();
return _deezerAPI.removeFavorite(currentMediaItem.id);
}
cache.libraryTracks.add(currentMediaItem.id);
_broadcastState();
return _deezerAPI.addFavoriteTrack(currentMediaItem.id);
}
//Remove item from queue
@override
Future<void> removeQueueItem(MediaItem mediaItem) async {
@ -415,13 +399,9 @@ class AudioPlayerTask extends BaseAudioHandler {
@override
Future<void> skipToPrevious() async {
if (_queueIndex == 0) return;
//Update buffering state
//_skipState = AudioProcessingState.skippingToPrevious;
//Normal skip to previous
unawaited(_logListenedTrack(currentMediaItem.id, sync: false, prev: true));
_queueIndex--;
await _player.seekToPrevious();
//_skipState = null;
}
Future<void> _logListenedTrack(String trackId,
@ -479,42 +459,52 @@ class AudioPlayerTask extends BaseAudioHandler {
customAction: CustomMediaAction(name: 'favorite'));
}
Future<void> toggleFavoriteCurrent() async {
// (un)favourite action
if (cache.libraryTracks.contains(currentMediaItem.id)) {
cache.libraryTracks.remove(currentMediaItem.id);
_broadcastState();
await _deezerAPI.removeFavorite(currentMediaItem.id);
return;
}
cache.libraryTracks.add(currentMediaItem.id);
_broadcastState();
await _deezerAPI.addFavoriteTrack(currentMediaItem.id);
}
//Update state on all clients
void _broadcastState() {
final controls = !currentMediaItemIsShow
? [
if (queue.value.isNotEmpty) favoriteControl(),
if (_queueIndex != 0) MediaControl.skipToPrevious,
_player.playing ? MediaControl.pause : MediaControl.play,
MediaControl.stop,
if (queue.hasValue && _queueIndex != queue.value.length - 1)
MediaControl.skipToNext,
]
: [
const MediaControl(
androidIcon: 'drawable/ic_replay_30',
label: 'replay 30',
action: MediaAction.rewind,
), // acts as prev-30
_player.playing ? MediaControl.pause : MediaControl.play,
MediaControl.stop,
const MediaControl(
androidIcon: 'drawable/ic_forward_30',
label: 'forward 30',
action: MediaAction.fastForward,
), // next-30
];
playbackState.add(PlaybackState(
controls: !currentMediaItemIsShow
? [
if (queue.value.isNotEmpty) favoriteControl(),
/*if (_queueIndex != 0)*/ MediaControl.skipToPrevious,
_player.playing ? MediaControl.pause : MediaControl.play,
/**/ MediaControl.skipToNext,
//Stop -- USELESS.
// MediaControl(
// androidIcon: 'drawable/ic_action_stop',
// label: 'stop',
// action: MediaAction.stop),
// i mean, the user can just swipe the notification away to stop
]
: [
const MediaControl(
androidIcon: 'drawable/ic_replay_30',
label: 'replay 30',
action: MediaAction.rewind,
), // acts as prev-30
_player.playing ? MediaControl.pause : MediaControl.play,
const MediaControl(
androidIcon: 'drawable/ic_forward_30',
label: 'forward 30',
action: MediaAction.fastForward,
), // next-30
],
controls: controls,
systemActions: !currentMediaItemIsShow
? {
? const {
MediaAction.seek,
if (queue.hasValue && _queueIndex != queue.value.length - 1)
MediaAction.skipToNext,
if (_queueIndex != 0) MediaAction.skipToPrevious,
MediaAction.stop
MediaAction.seekForward,
MediaAction.seekBackward,
}
: const {
MediaAction.seek,
@ -527,8 +517,9 @@ class AudioPlayerTask extends BaseAudioHandler {
bufferedPosition: _player.bufferedPosition,
speed: _player.speed,
queueIndex: _queueIndex,
androidCompactActionIndices:
!currentMediaItemIsShow ? const [1, 2, 3] : const [0, 1, 2],
androidCompactActionIndices: List.generate(controls.length, (i) => i)
.whereNot((i) => controls[i].action == MediaAction.stop)
.toList(growable: false),
repeatMode: _repeatMode,
shuffleMode: _originalQueue == null
? AudioServiceShuffleMode.none
@ -536,16 +527,16 @@ class AudioPlayerTask extends BaseAudioHandler {
));
}
//just_audio state -> audio_service state. If skipping, use _skipState
//just_audio state -> audio_service state.
AudioProcessingState _convertProcessingState(
ProcessingState processingState) {
return const <ProcessingState, AudioProcessingState>{
ProcessingState.idle: AudioProcessingState.idle,
ProcessingState.loading: AudioProcessingState.loading,
ProcessingState.buffering: AudioProcessingState.buffering,
ProcessingState.ready: AudioProcessingState.ready,
ProcessingState.completed: AudioProcessingState.completed,
}[processingState]!;
return switch (processingState) {
ProcessingState.idle => AudioProcessingState.idle,
ProcessingState.loading => AudioProcessingState.loading,
ProcessingState.buffering => AudioProcessingState.buffering,
ProcessingState.ready => AudioProcessingState.ready,
ProcessingState.completed => AudioProcessingState.completed,
};
}
//Replace current queue
@ -699,6 +690,8 @@ class AudioPlayerTask extends BaseAudioHandler {
case 'setIndex':
_queueIndex = extras!['index'];
break;
case 'favorite':
toggleFavoriteCurrent();
//Start visualizer
// case 'startVisualizer':
// if (_visualizerSubscription != null) break;

View File

@ -166,8 +166,8 @@ class MenuSheet {
title: option.label,
leading: option.icon,
onTap: () {
option.onTap.call();
Navigator.pop(context);
option.onTap.call();
},
))
.toList(growable: false)),
@ -367,10 +367,7 @@ class MenuSheet {
onTap: () {
navigatorKey.currentState!
.push(MaterialPageRoute(builder: (context) => ArtistDetails(a)));
if (navigateCallback != null) {
navigateCallback!();
}
navigateCallback?.call();
},
);
@ -385,9 +382,7 @@ class MenuSheet {
navigatorKey.currentState!
.push(MaterialPageRoute(builder: (context) => AlbumDetails(a)));
if (navigateCallback != null) {
navigateCallback!();
}
navigateCallback?.call();
},
);
@ -686,7 +681,9 @@ class MenuSheet {
);
MenuSheetOption wakelock() => MenuSheetOption(
Text('Keep the screen on'.i18n),
Text(cache.wakelock
? 'Don\'t keep screen on'.i18n
: 'Keep the screen on'.i18n),
icon: const Icon(Icons.screen_lock_portrait),
onTap: () async {
//Enable

View File

@ -31,6 +31,7 @@ import 'package:marquee/marquee.dart';
import 'package:palette_generator/palette_generator.dart';
import 'package:photo_view/photo_view.dart';
import 'package:provider/provider.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
const _blurStrength = 90.0;
@ -949,11 +950,19 @@ class _BigAlbumArtState extends State<BigAlbumArt> with WidgetsBindingObserver {
super.dispose();
}
void _pushLyrics() {
void _pushLyrics() async {
// enable wakelock if not already enabled
final wakelockChanged = !(await WakelockPlus.enabled);
if (wakelockChanged) {
WakelockPlus.enable();
}
builder(ctx) => ChangeNotifierProvider<BackgroundProvider>.value(
value: Provider.of<BackgroundProvider>(context),
child: const LyricsScreen());
Navigator.of(context).pushRoute(builder: builder);
final pushed = Navigator.of(context).pushRoute(builder: builder);
if (wakelockChanged) {
pushed.then((_) => WakelockPlus.disable());
}
}
@override
@ -1044,9 +1053,9 @@ class _BigAlbumArtState extends State<BigAlbumArt> with WidgetsBindingObserver {
)),
);
return Center(
child: AspectRatio(
aspectRatio: 1.0,
return AspectRatio(
aspectRatio: 1.0,
child: Center(
child: settings.playerAlbumArtDropShadow
? Consumer<BackgroundProvider>(
builder: (context, background, child) => AnimatedContainer(

View File

@ -1538,13 +1538,15 @@ class _GeneralSettingsState extends State<GeneralSettings> {
ScaffoldMessenger.of(context).snack('Copied'.i18n);
},
),
// ListTile(
// title: const Text('DEBUG: stop audioHandler'),
// onTap: () => audioHandler.stop()),
// ListTile(
// title: const Text('DEBUG: show login screen'),
// onTap: () => Navigator.of(context, rootNavigator: true)
// .pushRoute(builder: (ctx) => LoginWidget())),
if (kDebugMode) ...[
ListTile(
title: const Text('DEBUG: stop audioHandler'),
onTap: () => audioHandler.stop()),
ListTile(
title: const Text('DEBUG: show login screen'),
onTap: () => Navigator.of(context, rootNavigator: true)
.pushRoute(builder: (ctx) => LoginWidget())),
],
],
),
);

View File

@ -73,7 +73,7 @@ apply_standard_settings(${BINARY_NAME})
# Add dependency libraries. Add any application-specific dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
target_link_libraries(${BINARY_NAME} PRIVATE ${MIMALLOC_LIB})
# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)

View File

@ -19,7 +19,7 @@ if [ ! -w "$APPLICATIONS_DIR" ]; then
exit 1
fi
cat <<EOF
cat <<EOF > "$APPLICATIONS_DIR/freezer.desktop"
[Desktop Entry]
Type=Application
Name=freezer
@ -30,5 +30,5 @@ Icon=$ICON
Categories=Audio;Music;Player;AudioVideo;
Keywords=Music;Player;Streaming;Online;
Terminal=false
EOF > "$APPLICATIONS_DIR/freezer.desktop"
EOF

View File

@ -390,10 +390,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.2"
file:
dependency: transitive
description:
@ -524,10 +524,10 @@ packages:
dependency: transitive
description:
name: flutter_local_notifications_platform_interface
sha256: "7cf643d6d5022f3baed0be777b0662cce5919c0a7b86e700299f22dc4ae660ef"
sha256: "340abf67df238f7f0ef58f4a26d2a83e1ab74c77ab03cd2b2d5018ac64db30b7"
url: "https://pub.dev"
source: hosted
version: "7.0.0+1"
version: "7.1.0"
flutter_localizations:
dependency: "direct main"
description: flutter
@ -595,10 +595,10 @@ packages:
dependency: "direct main"
description:
name: get_it
sha256: e6017ce7fdeaf218dc51a100344d8cb70134b80e28b760f8bb23c242437bafd7
sha256: d85128a5dae4ea777324730dc65edd9c9f43155c109d5cc0a69cab74139fbac1
url: "https://pub.dev"
source: hosted
version: "7.6.7"
version: "7.7.0"
gettext_parser:
dependency: transitive
description:
@ -619,10 +619,10 @@ packages:
dependency: "direct main"
description:
name: google_fonts
sha256: "5b1726fee554d1cc9db1baef8061b126567ff0a1140a03ed7de936e62f2ab98b"
sha256: b1ac0fe2832c9cc95e5e88b57d627c5e68c223b9657f4b96e1487aa9098c7b82
url: "https://pub.dev"
source: hosted
version: "6.2.0"
version: "6.2.1"
graphs:
dependency: transitive
description:
@ -635,10 +635,10 @@ packages:
dependency: transitive
description:
name: hashlib
sha256: "0f8ae37da8350f50576406a0554e272cb2ecee8501fd8772ffb0dfaab464cfaa"
sha256: b9e2528c341c8e060f410bf049b18aea06218e77f857562bd18e8cc2e003e467
url: "https://pub.dev"
source: hosted
version: "1.13.1"
version: "1.14.0"
hashlib_codecs:
dependency: transitive
description:
@ -787,18 +787,18 @@ packages:
dependency: "direct main"
description:
name: json_annotation
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
url: "https://pub.dev"
source: hosted
version: "4.8.1"
version: "4.9.0"
json_serializable:
dependency: "direct dev"
description:
name: json_serializable
sha256: aa1f5a8912615733e0fdc7a02af03308933c93235bdc8d50d0b0c8a8ccb0b969
sha256: ea1432d167339ea9b5bb153f0571d0039607a873d6e04e0117af043f14a1fd4b
url: "https://pub.dev"
source: hosted
version: "6.7.1"
version: "6.8.0"
just_audio:
dependency: "direct main"
description:
@ -1195,10 +1195,10 @@ packages:
dependency: "direct main"
description:
name: pointycastle
sha256: "70fe966348fe08c34bf929582f1d8247d9d9408130723206472b4687227e4333"
sha256: "79fbafed02cfdbe85ef3fd06c7f4bc2cbcba0177e61b765264853d4253b21744"
url: "https://pub.dev"
source: hosted
version: "3.8.0"
version: "3.9.0"
pool:
dependency: transitive
description:
@ -1393,18 +1393,18 @@ packages:
dependency: "direct main"
description:
name: sqflite
sha256: a9016f495c927cb90557c909ff26a6d92d9bd54fc42ba92e19d4e79d61e798c6
sha256: "5ce2e1a15e822c3b4bfb5400455775e421da7098eed8adc8f26298ada7c9308c"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.3"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
sha256: "28d8c66baee4968519fb8bd6cdbedad982d6e53359091f0b74544a9f32ec72d5"
sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4"
url: "https://pub.dev"
source: hosted
version: "2.5.3"
version: "2.5.4"
stack_trace:
dependency: transitive
description:
@ -1473,10 +1473,10 @@ packages:
dependency: transitive
description:
name: timezone
sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0"
sha256: a6ccda4a69a442098b602c44e61a1e2b4bf6f5516e875bbf0f427d5df14745d5
url: "https://pub.dev"
source: hosted
version: "0.9.2"
version: "0.9.3"
timing:
dependency: transitive
description:
@ -1657,10 +1657,10 @@ packages:
dependency: transitive
description:
name: wakelock_plus_platform_interface
sha256: "40fabed5da06caff0796dc638e1f07ee395fb18801fbff3255a2372db2d80385"
sha256: "422d1cdbb448079a8a62a5a770b69baa489f8f7ca21aef47800c726d404f9d16"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.2.1"
watcher:
dependency: transitive
description:
@ -1673,18 +1673,18 @@ packages:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "0.4.2"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
sha256: "939ab60734a4f8fa95feacb55804fa278de28bdeef38e616dc08e44a84adea23"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
version: "2.4.3"
webview_flutter:
dependency: "direct main"
description:
@ -1721,10 +1721,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8"
sha256: "0eaf06e3446824099858367950a813472af675116bf63f008a4c2a75ae13e9cb"
url: "https://pub.dev"
source: hosted
version: "5.2.0"
version: "5.5.0"
window_manager:
dependency: "direct main"
description:
@ -1766,5 +1766,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.3 <4.0.0"
flutter: ">=3.16.6"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.2"