fix(playback): 播放页/迷你播放器立即显示已有封面,不再等元数据流程

原因有两层:
1) Song 模型没有封面路径,播放时只带 url/title/artist,
   播放页只能等元数据服务返回 artwork 字节后才显示;
2) 元数据回来后用新 Song 覆盖当前歌曲时丢了 artworkPath,
   即使带上了也会被冲掉。

- Song 增加 artworkPath 字段
- PlaybackController / 首页收藏 / playPlaylist 构造 Song 时带上
- 播放页:artwork 字节优先,其次直接读 artwork_path 文件
- 迷你播放器同样加 FileImage 兜底
- 元数据更新重建 Song 时保留 artworkPath

真机验证:点击播放后封面立即出现,不再先显示音符占位。
This commit is contained in:
2026-11-01 16:15:49 +08:00
parent a927e3dd44
commit 708ab91ccb
5 changed files with 48 additions and 11 deletions
+20 -8
View File
@@ -1,3 +1,4 @@
import 'dart:io';
// lib/pages/player_page.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@@ -322,6 +323,11 @@ class _PlayerPageState extends BaseState<PlayerPage> {
? (screen.height * 0.38).clamp(160.0, 380.0)
: null;
final artworkPath = song.artworkPath;
final hasArtworkFile = artworkPath != null &&
artworkPath.isNotEmpty &&
File(artworkPath).existsSync();
final cover = ClipRRect(
borderRadius: BorderRadius.circular(compact ? 18 : 24),
child: song.artwork != null
@@ -330,14 +336,20 @@ class _PlayerPageState extends BaseState<PlayerPage> {
fit: BoxFit.cover,
gaplessPlayback: true,
)
: Container(
color: const Color(0xFF2A3332),
child: Icon(
Icons.music_note,
size: compact ? 48 : 72,
color: Colors.white24,
),
),
: hasArtworkFile
? Image.file(
File(artworkPath),
fit: BoxFit.cover,
gaplessPlayback: true,
)
: Container(
color: const Color(0xFF2A3332),
child: Icon(
Icons.music_note,
size: compact ? 48 : 72,
color: Colors.white24,
),
),
);
final padded = Padding(