通知中心封面图显示
部分界面的信息更新 缓存系统初步引入 即将进入播放列表更新
This commit is contained in:
@@ -16,6 +16,10 @@ class MetadataCache {
|
||||
_cache[fileId] = metadata;
|
||||
}
|
||||
|
||||
Future<void> remove(String fileId) async {
|
||||
_cache.remove(fileId);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getHistory(String artist,
|
||||
{int limit = 10}) async {
|
||||
return [];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// lib/metadata/metadata_reader.dart
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:audio_metadata_reader/audio_metadata_reader.dart' as amr;
|
||||
import 'metadata_model.dart';
|
||||
@@ -7,13 +8,25 @@ import 'metadata_model.dart';
|
||||
class MetadataReader {
|
||||
Future<RawMetadata> readRawMetadata(File file) async {
|
||||
try {
|
||||
// ⭐ getImage: true 读取封面图
|
||||
final meta = amr.readMetadata(file, getImage: true);
|
||||
|
||||
// ⭐ 提取第一张图片
|
||||
debugPrint('📢 [MetadataReader] pictures count: ${meta.pictures.length}');
|
||||
|
||||
Uint8List? artwork;
|
||||
if (meta.pictures != null && meta.pictures!.isNotEmpty) {
|
||||
artwork = meta.pictures.first.bytes;
|
||||
if (meta.pictures.isNotEmpty) {
|
||||
try {
|
||||
final pic = meta.pictures.first;
|
||||
// 尝试获取图片数据,兼容不同字段名
|
||||
artwork = (pic as dynamic).bytes ?? (pic as dynamic).data;
|
||||
if (artwork != null) {
|
||||
debugPrint(
|
||||
'📢 [MetadataReader] artwork extracted: ${artwork.length} bytes');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ [MetadataReader] artwork extraction failed: $e');
|
||||
}
|
||||
} else {
|
||||
debugPrint('📢 [MetadataReader] no artwork found');
|
||||
}
|
||||
|
||||
return RawMetadata(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// lib/metadata/metadata_service.dart
|
||||
import 'dart:io'; // ⭐ 添加这一行
|
||||
import 'dart:typed_data'; // ⭐ 如果已经有更好
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../database/song_database.dart';
|
||||
import 'metadata_model.dart';
|
||||
@@ -32,6 +32,17 @@ class MetadataService {
|
||||
return LocalFileProvider();
|
||||
}
|
||||
|
||||
/// 公开给 AudioService 使用(用于清除缓存时获取文件)
|
||||
FileProvider getProviderForUrl(String url) {
|
||||
return _getProvider(url);
|
||||
}
|
||||
|
||||
/// 清除内存缓存
|
||||
Future<void> clearCache(String fileId) async {
|
||||
await _memoryCache.remove(fileId);
|
||||
debugPrint('🗑️ [MetadataService] memory cache cleared: $fileId');
|
||||
}
|
||||
|
||||
Future<FinalMetadata> getMetadata({
|
||||
required String url,
|
||||
required String fileName,
|
||||
@@ -111,6 +122,8 @@ class MetadataService {
|
||||
final history = await _db.getSongsByArtist(normalized.artist, limit: 10);
|
||||
final candidate = _normalizer.evaluate(normalized, history);
|
||||
final finalMetadata = _normalizer.decide(candidate);
|
||||
debugPrint(
|
||||
'📢 [MetadataService] finalMetadata.artwork is ${finalMetadata.artwork != null ? 'not null (${finalMetadata.artwork!.length} bytes)' : 'null'}');
|
||||
|
||||
// 7. 保存封面图到本地
|
||||
String? artworkPath;
|
||||
|
||||
Reference in New Issue
Block a user