Skip to content

Commit

Permalink
fix: icy image double loading (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Aug 30, 2024
1 parent 87d0147 commit df7b394
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 169 deletions.
1 change: 1 addition & 0 deletions lib/common/view/header_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class SidebarButton extends StatelessWidget {
},
icon: Icon(
Iconz().sidebar,
size: iconSize,
),
),
);
Expand Down
6 changes: 5 additions & 1 deletion lib/common/view/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,11 @@ class Iconz {

double get sideBarImageSize => 38;

double get iconSize => yaruStyled ? kYaruIconSize : 24;
double get iconSize => yaruStyled
? kYaruIconSize
: isMobile
? 24.0
: 20.0;

IconData getIconForTag(String tag) {
final tagsToIcons = <String, IconData>{
Expand Down
89 changes: 0 additions & 89 deletions lib/common/view/icy_image.dart

This file was deleted.

7 changes: 6 additions & 1 deletion lib/common/view/search_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ class SearchButton extends StatelessWidget {
Icon(
Iconz().search,
color: context.t.colorScheme.primary,
size: iconSize,
),
icon: icon ??
Icon(
Iconz().search,
size: iconSize,
),
icon: icon ?? Icon(Iconz().search),
);
}
}
8 changes: 0 additions & 8 deletions lib/common/view/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ ThemeData? yaruDarkWithTweaks(YaruThemeData yaru) {
space: 1.0,
thickness: 0.0,
),
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
actionTextColor: yaru.theme?.colorScheme.primary,
),
cardColor: yaru.darkTheme?.cardColor.scale(
lightness: -0.2,
),
Expand All @@ -37,10 +33,6 @@ ThemeData? yaruLightWithTweaks(YaruThemeData yaru) {
actionIconTheme: ActionIconThemeData(
backButtonIconBuilder: (context) => Icon(Iconz().goBack),
),
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
actionTextColor: yaru.theme?.colorScheme.primary,
),
cardColor: yaru.theme?.dividerColor.scale(
lightness: -0.01,
),
Expand Down
1 change: 1 addition & 0 deletions lib/player/player_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PlayerModel extends SafeChangeNotifier {
);

Color? get color => _service.color;
String? get remoteImageUrl => _service.remoteImageUrl;

bool _isUpNextExpanded = false;
bool get isUpNextExpanded => _isUpNextExpanded;
Expand Down
28 changes: 21 additions & 7 deletions lib/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class PlayerService {
MpvMetaData? _mpvMetaData;
MpvMetaData? get mpvMetaData => _mpvMetaData;
void setMpvMetaData(MpvMetaData? value) {
if (value?.icyTitle == _mpvMetaData?.icyTitle) return;
_mpvMetaData = value;

var validHistoryElement = _mpvMetaData?.icyTitle.isNotEmpty == true;
Expand Down Expand Up @@ -218,7 +217,7 @@ class PlayerService {
);
}
_setMediaControlsMetaData(audio: audio!);
_loadColor();
_loadColorAndSetRemoteUrl();
_firstPlay = false;
} on Exception catch (_) {}
}
Expand Down Expand Up @@ -276,22 +275,25 @@ class PlayerService {
return;
}
final mpvMetaData = MpvMetaData.fromJson(data);

if (mpvMetaData.icyTitle == _mpvMetaData?.icyTitle) return;
setMpvMetaData(
mpvMetaData.copyWith(
icyTitle: HtmlParser(mpvMetaData.icyTitle).parseFragment().text,
),
);

final songInfo = mpvMetaData.icyTitle.splitByDash;
fetchAlbumArt(mpvMetaData.icyTitle).then(
(albumArt) {
_setMediaControlsMetaData(
(albumArt) async {
await _setMediaControlsMetaData(
audio: (_audio ?? const Audio()).copyWith(
imageUrl: albumArt,
title: songInfo.songName,
artist: songInfo.artist,
),
);
_loadColor(artUrl: albumArt);
await _loadColorAndSetRemoteUrl(artUrl: albumArt);
},
);
},
Expand Down Expand Up @@ -437,22 +439,34 @@ class PlayerService {
Color? _color;
Color? get color => _color;

Future<void> _loadColor({String? artUrl}) async {
String? _remoteImageUrl;
String? get remoteImageUrl => _remoteImageUrl;
void _setRemoteImageUrl(String? url) {
_remoteImageUrl = url;
_propertiesChangedController.add(true);
}

Future<void> _loadColorAndSetRemoteUrl({String? artUrl}) async {
final pic = CoverStore().get(_audio?.albumId);
if (pic == null &&
audio?.imageUrl == null &&
audio?.albumArtUrl == null &&
artUrl == null) {
_color = null;
_setRemoteImageUrl(null);

return;
}

ImageProvider? image;
if (pic != null) {
_setRemoteImageUrl(null);
image = MemoryImage(pic);
} else {
final url = artUrl ?? _audio!.imageUrl ?? _audio!.albumArtUrl!;
_setRemoteImageUrl(url);
image = NetworkImage(
artUrl ?? _audio!.imageUrl ?? _audio!.albumArtUrl!,
url,
);
}
final generator = await PaletteGenerator.fromImageProvider(image);
Expand Down
10 changes: 2 additions & 8 deletions lib/player/view/blurred_full_height_player_image.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:blur/blur.dart';
import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';

import '../../extensions/build_context_x.dart';
import '../../extensions/theme_data_x.dart';
import '../player_model.dart';
import 'full_height_player_image.dart';

class BlurredFullHeightPlayerImage extends StatelessWidget with WatchItMixin {
class BlurredFullHeightPlayerImage extends StatelessWidget {
const BlurredFullHeightPlayerImage({
super.key,
required this.size,
Expand All @@ -18,13 +16,8 @@ class BlurredFullHeightPlayerImage extends StatelessWidget with WatchItMixin {
@override
Widget build(BuildContext context) {
final theme = context.t;
final audio = watchPropertyValue((PlayerModel m) => m.audio);
final mpvMetaData = watchPropertyValue((PlayerModel m) => m.mpvMetaData);

return Opacity(
key: ValueKey(
'${audio?.path ?? ''}${mpvMetaData?.icyTitle ?? ''}${audio?.albumArtUrl ?? ''}${audio?.imageUrl ?? ''}',
),
opacity: theme.isLight ? 0.8 : 0.9,
child: SizedBox(
width: size.width,
Expand All @@ -35,6 +28,7 @@ class BlurredFullHeightPlayerImage extends StatelessWidget with WatchItMixin {
blurColor:
theme.isLight ? Colors.white : theme.scaffoldBackgroundColor,
child: FullHeightPlayerImage(
emptyFallBack: true,
borderRadius: BorderRadius.zero,
fit: BoxFit.cover,
height: size.height,
Expand Down
8 changes: 0 additions & 8 deletions lib/player/view/bottom_player_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:watch_it/watch_it.dart';
import '../../app/app_model.dart';
import '../../common/data/audio.dart';
import '../../local_audio/view/local_cover.dart';
import '../player_model.dart';
import 'player_fall_back_image.dart';
import 'player_remote_source_image.dart';

Expand Down Expand Up @@ -46,8 +45,6 @@ class BottomPlayerImage extends StatelessWidget with WatchItMixin {
);
}

final mpvMetaData = watchPropertyValue((PlayerModel m) => m.mpvMetaData);

Widget child;

final fallBackImage = PlayerFallBackImage(
Expand All @@ -67,13 +64,8 @@ class BottomPlayerImage extends StatelessWidget with WatchItMixin {
);
} else {
child = PlayerRemoteSourceImage(
key: ValueKey(
'${mpvMetaData?.icyTitle ?? ''}${audio?.albumArtUrl ?? ''}${audio?.imageUrl ?? ''}',
),
mpvMetaData: mpvMetaData,
height: size,
width: size,
audio: audio,
fit: BoxFit.cover,
fallBackIcon: fallBackImage,
errorIcon: fallBackImage,
Expand Down
10 changes: 3 additions & 7 deletions lib/player/view/full_height_player_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ class FullHeightPlayerImage extends StatelessWidget with WatchItMixin {
this.height,
this.width,
this.borderRadius,
this.emptyFallBack = false,
});

final BoxFit? fit;
final double? height, width;
final BorderRadius? borderRadius;
final bool emptyFallBack;

@override
Widget build(BuildContext context) {
final audio = watchPropertyValue((PlayerModel m) => m.audio);

final mpvMetaData = watchPropertyValue((PlayerModel m) => m.mpvMetaData);

final fallBackImage = PlayerFallBackImage(
noIcon: emptyFallBack,
audio: audio,
height: height ?? fullHeightPlayerImageSize,
width: width ?? fullHeightPlayerImageSize,
Expand All @@ -45,13 +46,8 @@ class FullHeightPlayerImage extends StatelessWidget with WatchItMixin {
);
} else {
image = PlayerRemoteSourceImage(
key: ValueKey(
'${mpvMetaData?.icyTitle ?? ''}${audio?.albumArtUrl ?? ''}${audio?.imageUrl ?? ''}',
),
mpvMetaData: mpvMetaData,
height: height ?? fullHeightPlayerImageSize,
width: width ?? fullHeightPlayerImageSize,
audio: audio,
fit: fit,
fallBackIcon: fallBackImage,
errorIcon: fallBackImage,
Expand Down
22 changes: 13 additions & 9 deletions lib/player/view/player_fall_back_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class PlayerFallBackImage extends StatelessWidget {
this.audio,
required this.height,
required this.width,
this.noIcon = false,
});

final Audio? audio;
final double height;
final double width;
final bool noIcon;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -55,15 +57,17 @@ class PlayerFallBackImage extends StatelessWidget {
),
width: width,
height: height,
child: Icon(
iconData,
size: iconSize,
color: contrastColor(
getAlphabetColor(
audio?.title ?? audio?.album ?? 'a',
),
),
),
child: noIcon
? null
: Icon(
iconData,
size: iconSize,
color: contrastColor(
getAlphabetColor(
audio?.title ?? audio?.album ?? 'a',
),
),
),
),
);
}
Expand Down
Loading

0 comments on commit df7b394

Please sign in to comment.