fix(playback): 歌单/文件列表播放时标题不再显示百分号编码

播放路径是编码的,无元数据时直接截取文件名会显示
"%E6%9C%AA%E5%88%86..." 这种串。

- playPlaylist:统一解码后再去扩展名,DB 标题为空也回退到解码名
- PlaybackController:单曲与队列构建同样走 _displayName()
- 有标签时仍优先用标签标题
This commit is contained in:
2026-11-01 16:34:44 +08:00
parent e10be527cb
commit 3a60cabca5
2 changed files with 40 additions and 21 deletions
+22 -16
View File
@@ -300,23 +300,29 @@ class AudioService extends ChangeNotifier {
final songs = <Song>[];
for (final id in songIds) {
final dbSong = await _db.getSongByPath(id);
if (dbSong != null) {
final path = dbSong['remote_path'] as String;
songs.add(Song(
id: path,
artworkPath: dbSong['artwork_path'] as String?,
title: dbSong['title'] as String? ?? '',
artist: dbSong['artist'] as String? ?? '未知艺术家',
url: WebDAVService.instance.getFileUrl(path),
));
} else {
songs.add(Song(
id: id,
title: id.split('/').last.replaceAll(RegExp(r'\.[^.]*$'), ''),
artist: '未知艺术家',
url: WebDAVService.instance.getFileUrl(id),
));
final path = (dbSong?['remote_path'] as String?) ?? id;
// 没有标签时回退文件名,必须解码:id 是百分号编码的播放路径,
// 直接展示会变成 "%E6%9C%AA..." 这种不可读串。
final rawName = path.split('/').last;
String displayName;
try {
displayName = Uri.decodeComponent(rawName);
} catch (_) {
displayName = rawName;
}
displayName = displayName.replaceAll(RegExp(r'\.[^.]*$'), '');
final dbTitle = (dbSong?['title'] as String?)?.trim() ?? '';
final dbArtist = (dbSong?['artist'] as String?)?.trim() ?? '';
songs.add(Song(
id: path,
artworkPath: dbSong?['artwork_path'] as String?,
title: dbTitle.isNotEmpty ? dbTitle : displayName,
artist: dbArtist.isNotEmpty ? dbArtist : '未知艺术家',
url: WebDAVService.instance.getFileUrl(path),
));
}
if (songs.isNotEmpty) {