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