部分界面调整,把底部的播放控件完整前置
This commit is contained in:
@@ -688,9 +688,6 @@ class _HomePageState extends State<HomePage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// ---- 底部 MiniPlayer ----
|
||||
if (showMiniBar) const MiniPlayerBar(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
// lib/pages/playlist_page.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../services/audio_service.dart';
|
||||
|
||||
class PlaylistPage extends StatelessWidget {
|
||||
const PlaylistPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final service = context.watch<AudioService>();
|
||||
final queue = service.queue;
|
||||
final currentIndex = service.currentIndex;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF0E1211),
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'播放列表',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
foregroundColor: Colors.white,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear_all, color: Colors.white54),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: const Color(0xFF1A1F1E),
|
||||
title: const Text(
|
||||
'清空播放列表',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
content: const Text(
|
||||
'确定要清空当前播放列表吗?',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
service.clearQueue();
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text(
|
||||
'清空',
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: queue.isEmpty
|
||||
? const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.playlist_play, size: 48, color: Colors.grey),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'播放列表为空',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
itemCount: queue.length,
|
||||
itemBuilder: (context, index) {
|
||||
final song = queue[index];
|
||||
final isCurrent = index == currentIndex;
|
||||
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
leading: Icon(
|
||||
isCurrent ? Icons.play_arrow : Icons.music_note,
|
||||
color:
|
||||
isCurrent ? const Color(0xFFB8D4D0) : Colors.grey[600],
|
||||
size: 24,
|
||||
),
|
||||
title: Text(
|
||||
song.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: isCurrent ? FontWeight.w600 : FontWeight.w400,
|
||||
color: isCurrent ? Colors.white : Colors.grey[300],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(
|
||||
song.artist,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: isCurrent ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: isCurrent
|
||||
? Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFB8D4D0).withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'正在播放',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Color(0xFFB8D4D0),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
onTap: () {
|
||||
service.setQueue(queue, startIndex: index);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
// lib/pages/webdav_file_list_page.dart
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../services/webdav_service.dart';
|
||||
import '../services/playback_service.dart';
|
||||
import '../services/audio_service.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
class WebDAVFileListPage extends StatefulWidget {
|
||||
final String currentPath;
|
||||
@@ -27,7 +26,7 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
try {
|
||||
return Uri.decodeComponent(input);
|
||||
} catch (_) {
|
||||
return input; // 解码失败时返回原始字符串
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +37,9 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
_loadDirectory();
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 加载目录
|
||||
// ============================================================
|
||||
Future<void> _loadDirectory() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
@@ -59,6 +61,9 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 进入子目录
|
||||
// ============================================================
|
||||
void _enterDirectory(WebDAVItem dir) {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -68,19 +73,19 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ⭐ 核心:播放歌曲 + 自动构建队列
|
||||
// ============================================================
|
||||
void _playSong(WebDAVItem file) async {
|
||||
try {
|
||||
final url = WebDAVService.instance.getFileUrl(file.path);
|
||||
// 1. 获取当前目录所有音乐文件(过滤掉目录)
|
||||
final musicFiles = _items.where((item) => !item.isDirectory).toList();
|
||||
|
||||
// ✅ 动态获取认证头(从 SharedPreferences 读取)
|
||||
final headers = await WebDAVService.instance.getAuthHeaders();
|
||||
|
||||
if (headers.isEmpty) {
|
||||
print('⚠️ 未获取到认证头,请检查 WebDAV 登录状态');
|
||||
if (musicFiles.isEmpty) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('请先登录 WebDAV'),
|
||||
content: Text('当前目录没有音乐文件'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
@@ -88,18 +93,57 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
return;
|
||||
}
|
||||
|
||||
print('🎵 [文件列表] 播放 URL: $url');
|
||||
print('📋 [文件列表] 认证头已设置: ${headers.keys}');
|
||||
// 2. 获取认证头
|
||||
final headers = await WebDAVService.instance.getAuthHeaders();
|
||||
|
||||
final song = Song(
|
||||
id: file.path,
|
||||
title: file.name.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
artist: '未知艺术家',
|
||||
url: url,
|
||||
);
|
||||
context.read<AudioService>().playSong(song);
|
||||
// 3. 构建播放队列(所有音乐文件)
|
||||
final queue = musicFiles.map((item) {
|
||||
final itemUrl = WebDAVService.instance.getFileUrl(item.path);
|
||||
return Song(
|
||||
id: item.path,
|
||||
title: item.name.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
artist: '未知艺术家',
|
||||
url: itemUrl,
|
||||
);
|
||||
}).toList();
|
||||
|
||||
await PlaybackService().play(url, headers: headers);
|
||||
// 4. 找到当前点击歌曲在队列中的位置
|
||||
final startIndex = queue.indexWhere((s) => s.id == file.path);
|
||||
if (startIndex == -1) {
|
||||
// 极端情况:队列构建有问题,退化为单曲播放
|
||||
final url = WebDAVService.instance.getFileUrl(file.path);
|
||||
final song = Song(
|
||||
id: file.path,
|
||||
title: file.name.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
artist: '未知艺术家',
|
||||
url: url,
|
||||
);
|
||||
context.read<AudioService>().setQueue([song], startIndex: 0);
|
||||
await PlaybackService().play(url, headers: headers);
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. 设置队列并播放
|
||||
final audioService = context.read<AudioService>();
|
||||
audioService.setQueue(queue, startIndex: startIndex);
|
||||
|
||||
// 6. 播放(AudioService 内部已经调用了 PlaybackService,但为了确保认证头传递)
|
||||
// 这里再显式调用一下,确保认证头正确
|
||||
final targetUrl = queue[startIndex].url!;
|
||||
await PlaybackService().play(targetUrl, headers: headers);
|
||||
|
||||
// 7. 更新 AudioService 的播放状态(确保 UI 同步)
|
||||
// setQueue 已经调用了 _playCurrent(),所以这里不需要重复调用
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('正在播放: ${file.name}'),
|
||||
backgroundColor: const Color(0xFF4CAF50),
|
||||
duration: const Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -112,6 +156,67 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 全部播放(从第一首开始)
|
||||
// ============================================================
|
||||
void _playAll() async {
|
||||
try {
|
||||
final musicFiles = _items.where((item) => !item.isDirectory).toList();
|
||||
|
||||
if (musicFiles.isEmpty) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('当前目录没有音乐文件'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final headers = await WebDAVService.instance.getAuthHeaders();
|
||||
|
||||
final queue = musicFiles.map((item) {
|
||||
final itemUrl = WebDAVService.instance.getFileUrl(item.path);
|
||||
return Song(
|
||||
id: item.path,
|
||||
title: item.name.replaceAll(RegExp(r'\.[^.]*$'), ''),
|
||||
artist: '未知艺术家',
|
||||
url: itemUrl,
|
||||
);
|
||||
}).toList();
|
||||
|
||||
final audioService = context.read<AudioService>();
|
||||
audioService.setQueue(queue, startIndex: 0);
|
||||
|
||||
final targetUrl = queue[0].url!;
|
||||
await PlaybackService().play(targetUrl, headers: headers);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('开始播放全部 (${queue.length}首)'),
|
||||
backgroundColor: const Color(0xFF4CAF50),
|
||||
duration: const Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('播放失败: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 显示路径
|
||||
// ============================================================
|
||||
String _getDisplayPath() {
|
||||
if (_currentPath == '/' || _currentPath.isEmpty) return '根目录';
|
||||
|
||||
@@ -123,6 +228,9 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
return '... / ${parts.sublist(parts.length - 2).join(' / ')}';
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Build
|
||||
// ============================================================
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -140,6 +248,12 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
actions: [
|
||||
// 全部播放按钮
|
||||
IconButton(
|
||||
icon: const Icon(Icons.playlist_play),
|
||||
onPressed: _playAll,
|
||||
tooltip: '全部播放',
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: _loadDirectory,
|
||||
@@ -211,6 +325,9 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 构建列表项
|
||||
// ============================================================
|
||||
Widget _buildListItem(WebDAVItem item) {
|
||||
final displayName = _safeDecode(item.name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user