fix(playback): 歌单/文件列表播放时标题不再显示百分号编码
播放路径是编码的,无元数据时直接截取文件名会显示 "%E6%9C%AA%E5%88%86..." 这种串。 - playPlaylist:统一解码后再去扩展名,DB 标题为空也回退到解码名 - PlaybackController:单曲与队列构建同样走 _displayName() - 有标签时仍优先用标签标题
This commit is contained in:
@@ -92,6 +92,17 @@ class PlaybackController {
|
||||
// ════════════════════════════════════════════════════════════
|
||||
// 单曲播放(fallback)
|
||||
// ════════════════════════════════════════════════════════════
|
||||
/// 播放路径/文件名是百分号编码的,展示前必须解码
|
||||
String _displayName(String pathOrName) {
|
||||
final raw = pathOrName.split('/').last;
|
||||
String decoded;
|
||||
try {
|
||||
decoded = Uri.decodeComponent(raw);
|
||||
} catch (_) {
|
||||
decoded = raw;
|
||||
}
|
||||
return decoded.replaceAll(RegExp(r'\.[^.]*$'), '');
|
||||
}
|
||||
Future<void> _playSingleSong(String songPath) async {
|
||||
debugPrint('🎯 [PlaybackController] _playSingleSong: $songPath');
|
||||
final url = WebDAVService.instance.getFileUrl(songPath);
|
||||
@@ -99,8 +110,9 @@ class PlaybackController {
|
||||
final song = Song(
|
||||
id: songPath,
|
||||
artworkPath: dbSong?['artwork_path'] as String?,
|
||||
title: dbSong?['title'] as String? ??
|
||||
songPath.split('/').last.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
title: (dbSong?['title'] as String?)?.trim().isNotEmpty == true
|
||||
? dbSong!['title'] as String
|
||||
: _displayName(songPath),
|
||||
artist: dbSong?['artist'] as String? ?? '未知艺术家',
|
||||
url: url,
|
||||
);
|
||||
@@ -119,15 +131,16 @@ class PlaybackController {
|
||||
queue.add(Song(
|
||||
id: item.path,
|
||||
artworkPath: dbSong['artwork_path'] as String?,
|
||||
title: dbSong['title'] as String? ??
|
||||
item.name.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
title: (dbSong['title'] as String?)?.trim().isNotEmpty == true
|
||||
? dbSong['title'] as String
|
||||
: _displayName(item.path),
|
||||
artist: dbSong['artist'] as String? ?? '未知艺术家',
|
||||
url: url,
|
||||
));
|
||||
} else {
|
||||
queue.add(Song(
|
||||
id: item.path,
|
||||
title: item.name.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
title: _displayName(item.path),
|
||||
artist: '未知艺术家',
|
||||
url: url,
|
||||
));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user