Skip to content

Commit 55a0876

Browse files
authored
chore: add resetRemoteSource option in updateState and improve remote art handling (#112)
1 parent f39ce58 commit 55a0876

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

lib/player/player_manager.dart

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:safe_change_notifier/safe_change_notifier.dart';
88
import 'package:yaru/yaru.dart';
99

1010
import '../common/logging.dart';
11-
import '../extensions/string_x.dart';
1211
import 'data/local_media.dart';
1312
import 'data/unique_media.dart';
1413
import 'view/player_view_state.dart';
@@ -56,6 +55,7 @@ class PlayerManager extends BaseAudioHandler with SeekHandler {
5655
Color? color,
5756
String? remoteSourceArtUrl,
5857
String? remoteSourceTitle,
58+
bool resetRemoteSource = false,
5959
}) {
6060
final previousArtUri = mediaItem.value?.artUri;
6161
final artUri =
@@ -64,22 +64,32 @@ class PlayerManager extends BaseAudioHandler with SeekHandler {
6464
: Uri.tryParse(remoteSourceArtUrl)) ??
6565
previousArtUri;
6666

67-
playerViewState.value = playerViewState.value.copyWith(
68-
fullMode: fullMode,
69-
showPlayerExplorer: showPlayerExplorer,
70-
explorerIndex: explorerIndex,
71-
color: color,
72-
remoteSourceArtUrl: artUri.toString(),
73-
remoteSourceTitle: remoteSourceTitle,
74-
);
67+
if (resetRemoteSource) {
68+
playerViewState.value = PlayerViewState(
69+
fullMode: fullMode ?? playerViewState.value.fullMode,
70+
showPlayerExplorer:
71+
showPlayerExplorer ?? playerViewState.value.showPlayerExplorer,
72+
explorerIndex: explorerIndex ?? playerViewState.value.explorerIndex,
73+
color: color,
74+
remoteSourceArtUrl: null,
75+
remoteSourceTitle: null,
76+
);
77+
} else {
78+
playerViewState.value = playerViewState.value.copyWith(
79+
fullMode: fullMode,
80+
showPlayerExplorer: showPlayerExplorer,
81+
explorerIndex: explorerIndex,
82+
color: color,
83+
remoteSourceArtUrl: remoteSourceArtUrl,
84+
remoteSourceTitle: remoteSourceTitle,
85+
);
86+
}
7587

76-
if (remoteSourceTitle != null) {
77-
final split = remoteSourceTitle.splitByDash;
88+
if (remoteSourceTitle != null && mediaItem.value != null) {
7889
mediaItem.add(
79-
MediaItem(
80-
id: remoteSourceTitle,
90+
mediaItem.value?.copyWith(
8191
title: remoteSourceTitle,
82-
artist: currentMedia?.artist ?? split.artist,
92+
artist: currentMedia?.artist,
8393
artUri: artUri,
8494
),
8595
);
@@ -200,13 +210,7 @@ class PlayerManager extends BaseAudioHandler with SeekHandler {
200210

201211
Future<void> setPlaylist(List<UniqueMedia> mediaList, {int index = 0}) async {
202212
if (mediaList.isEmpty) return;
203-
updateState(
204-
remoteSourceArtUrl:
205-
mediaList.elementAtOrNull(index)?.artUrl?.endsWith('.ico') == true
206-
? null
207-
: mediaList.elementAtOrNull(index)?.artUrl,
208-
remoteSourceTitle: mediaList.elementAtOrNull(index)?.title,
209-
);
213+
updateState(resetRemoteSource: true);
210214
await _player.open(Playlist(mediaList, index: index));
211215
}
212216

lib/player/view/player_album_art.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ class PlayerRemoteSourceImage extends StatelessWidget with WatchItMixin {
7676
p.playerViewState.select((e) => e.remoteSourceArtUrl),
7777
);
7878

79+
final artUrl = watchStream(
80+
(PlayerManager p) => p.currentMediaStream.map((e) => e.artUrl),
81+
initialValue: di<PlayerManager>().currentMedia?.artUrl,
82+
).data;
83+
7984
final color = watchValue(
8085
(PlayerManager p) => p.playerViewState.select((e) => e.color),
8186
);
@@ -96,7 +101,7 @@ class PlayerRemoteSourceImage extends StatelessWidget with WatchItMixin {
96101
);
97102
},
98103
onImageLoaded: di<PlayerManager>().setRemoteColorFromImageProvider,
99-
url: remoteSourceArtUrl,
104+
url: remoteSourceArtUrl ?? artUrl,
100105
filterQuality: FilterQuality.medium,
101106
fit: fit ?? BoxFit.scaleDown,
102107
fallBackIcon: Icon(

lib/player/view/player_full_view.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:media_kit_video/media_kit_video.dart';
44
import 'package:watch_it/watch_it.dart';
55
import 'package:yaru/yaru.dart';
66

7+
import '../../common/platforms.dart';
78
import '../../common/view/build_context_x.dart';
89
import '../../common/view/theme.dart';
910
import '../../common/view/ui_constants.dart';
@@ -95,7 +96,7 @@ class PlayerFullView extends StatelessWidget
9596
title: Text('Media Player', style: TextStyle(color: iconColor)),
9697
backgroundColor: Colors.transparent,
9798
border: BorderSide.none,
98-
isClosable: false,
99+
isClosable: !Platforms.isMacOS,
99100
actions: [
100101
IconButton(
101102
isSelected: showPlayerExplorer,

0 commit comments

Comments
 (0)