引入部分缓存机制
引入封面图信息 正在进入测试阶段
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
// lib/metadata/metadata_reader.dart
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart'; // ⭐ 添加
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:audio_metadata_reader/audio_metadata_reader.dart' as amr;
|
||||
import 'metadata_model.dart';
|
||||
|
||||
class MetadataReader {
|
||||
Future<RawMetadata> readRawMetadata(File file) async {
|
||||
try {
|
||||
final meta = amr.readMetadata(file, getImage: false);
|
||||
// ⭐ getImage: true 读取封面图
|
||||
final meta = amr.readMetadata(file, getImage: true);
|
||||
|
||||
// ⭐ 提取第一张图片
|
||||
Uint8List? artwork;
|
||||
if (meta.pictures != null && meta.pictures!.isNotEmpty) {
|
||||
artwork = meta.pictures.first.bytes;
|
||||
}
|
||||
|
||||
return RawMetadata(
|
||||
title: meta.title ?? '',
|
||||
artist: meta.artist ?? '',
|
||||
album: meta.album ?? '',
|
||||
// ⭐ genres 和 performers 是非空 List<String>,不需要 ??
|
||||
genres: meta.genres,
|
||||
performers: meta.performers,
|
||||
year: _toInt(meta.year),
|
||||
@@ -22,6 +28,7 @@ class MetadataReader {
|
||||
discNumber: _toInt(meta.discNumber),
|
||||
totalDisc: _toInt(meta.totalDisc),
|
||||
duration: meta.duration,
|
||||
artwork: artwork,
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ [MetadataReader] read failed: $e');
|
||||
|
||||
Reference in New Issue
Block a user