Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback cover #1002

Open
wants to merge 3 commits into
base: redesign
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/placeholder-art.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 32 additions & 3 deletions lib/services/album_image_provider.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import 'dart:io';
import 'dart:typed_data';
import 'dart:async';
import 'dart:ui';

import 'package:finamp/models/finamp_models.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get_it/get_it.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';

import '../models/jellyfin_models.dart';
import 'downloads_service.dart';
Expand Down Expand Up @@ -45,7 +49,7 @@ final AutoDisposeProviderFamily<ImageProvider?, AlbumImageRequest>
albumImageProvider = Provider.autoDispose
.family<ImageProvider?, AlbumImageRequest>((ref, request) {
if (request.item.imageId == null) {
return null;
return FileImage(await getFallbackImageFile());
}

final jellyfinApiHelper = GetIt.instance<JellyfinApiHelper>();
Expand All @@ -56,7 +60,7 @@ final AutoDisposeProviderFamily<ImageProvider?, AlbumImageRequest>

if (downloadedImage?.file == null) {
if (FinampSettingsHelper.finampSettings.isOffline) {
return null;
return FileImage(await getFallbackImageFile());
}

Uri? imageUrl = jellyfinApiHelper.getImageUrl(
Expand All @@ -66,7 +70,7 @@ final AutoDisposeProviderFamily<ImageProvider?, AlbumImageRequest>
);

if (imageUrl == null) {
return null;
return FileImage(await getFallbackImageFile());
}

String? key;
Expand Down Expand Up @@ -97,6 +101,31 @@ final AutoDisposeProviderFamily<ImageProvider?, AlbumImageRequest>
return out;
});

Future<File> getFallbackImageFile() async {
return await getImageFile("images/placeholder-art.png");
}

Future<File> getImageFile(String imagePath) async {

final Directory tempDir = await getTemporaryDirectory();
final String tempPath = tempDir.path;
final String fileName = imagePath.split('/').last;

// test if file already exists
final File file = File('$tempPath/$fileName');
if (await file.exists()) {
return file;
}

// if not, load asset and write to file
final ByteData byteData = await rootBundle.load(imagePath);
final Uint8List bytes = byteData.buffer.asUint8List();

await file.writeAsBytes(bytes);

return file;
}

class CachedImage extends ImageProvider<CachedImage> {
CachedImage(ImageProvider base, this.cacheKey) : _base = base;

Expand Down
14 changes: 9 additions & 5 deletions lib/services/queue_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:finamp/components/global_snackbar.dart';
import 'package:finamp/gen/assets.gen.dart';
import 'package:finamp/models/finamp_models.dart';
import 'package:finamp/models/jellyfin_models.dart' as jellyfin_models;
import 'package:finamp/services/album_image_provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:get_it/get_it.dart';
import 'package:hive_flutter/hive_flutter.dart';
Expand Down Expand Up @@ -1057,11 +1058,12 @@ class QueueService {
if (artUri == null) {
final applicationSupportDirectory =
await getApplicationSupportDirectory();
artUri = Uri(
scheme: "content",
host: contentProviderPackageName,
path: path_helper.join(applicationSupportDirectory.absolute.path,
Assets.images.albumWhite.path));
// artUri = Uri(
// scheme: "content",
// host: contentProviderPackageName,
// path: path_helper.join(applicationSupportDirectory.absolute.path,
// Assets.images.albumWhite.path));
artUri = _jellyfinApiHelper.getImageUrl(item: item) ?? (await getFallbackImageFile()).uri;
} else {
// store the origin in fragment since it should be unused
artUri = Uri(
Expand All @@ -1074,6 +1076,8 @@ class QueueService {
}
}

_queueServiceLogger.fine("imageUri: $imageUri\ndownloadedImage: ${downloadedImage?.file != null}\njellyfinUri: ${_jellyfinApiHelper.getImageUrl(item: item)}\nfallbackUri: ${(await getFallbackImageFile()).uri}\nitem.imageId: ${item.imageId}\nitem.imageTags: ${item.imageTags}");

return MediaItem(
id: itemId?.toString() ?? uuid.v4(),
playable:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ flutter:
- images/finamp_cropped.png
- images/finamp_cropped.svg
- images/jellyfin-icon-transparent.png
- images/placeholder-art.png
# - images/a_dot_ham.jpeg

generate: true
Expand Down
Loading