现阶段基础播放能力已经实现,接下来将尽全力往UI方向再调整一下

This commit is contained in:
2026-08-17 23:10:24 +08:00
parent 725116760a
commit 7566700bed
3 changed files with 75 additions and 58 deletions
+19 -14
View File
@@ -9,7 +9,6 @@ import '../widgets/magnetic_scroll_physics.dart';
import 'webdav_setup_page.dart'; import 'webdav_setup_page.dart';
import 'webdav_file_list_page.dart'; import 'webdav_file_list_page.dart';
import 'dart:async'; import 'dart:async';
import 'dart:convert';
// ================================================== // ==================================================
// 歌曲数据模型 // 歌曲数据模型
@@ -258,15 +257,7 @@ class _HomePageState extends State<HomePage> {
try { try {
final url = WebDAVService.instance.getFileUrl(song.path); final url = WebDAVService.instance.getFileUrl(song.path);
// ✅ 硬编码认证头测试 // 1️⃣ 先更新 UI(立即响应)
final testHeaders = {
'Authorization':
'Basic ' + base64Encode(utf8.encode('test-user-1:Lxh10020328?')),
};
print('🎵 测试 URL: $url');
print('📋 测试认证头: ${testHeaders.keys}');
final audioService = context.read<AudioService>(); final audioService = context.read<AudioService>();
audioService.playSong(Song( audioService.playSong(Song(
id: song.path, id: song.path,
@@ -275,12 +266,26 @@ class _HomePageState extends State<HomePage> {
url: url, url: url,
)); ));
// 获取认证头 // 2️⃣ 动态获取认证头
final headers = await WebDAVService.instance.getAuthHeaders(); final headers = await WebDAVService.instance.getAuthHeaders();
print('📋 认证头数量: ${headers.length}');
print('📋 认证头内容: $headers');
// 播放 if (headers.isEmpty) {
print('⚠️ 未获取到认证头,请检查 WebDAV 登录状态');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('请先登录 WebDAV'),
backgroundColor: Colors.orange,
),
);
}
return;
}
print('🎵 [收藏列表] 播放 URL: $url');
print('📋 [收藏列表] 认证头已设置: ${headers.keys}');
// 3️⃣ 播放
await PlaybackService().play(url, headers: headers); await PlaybackService().play(url, headers: headers);
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
+39 -37
View File
@@ -11,17 +11,8 @@ class PlayerPage extends StatefulWidget {
} }
class _PlayerPageState extends State<PlayerPage> { class _PlayerPageState extends State<PlayerPage> {
// ✅ 使用 late,但不赋值,在 didChangeDependencies 中初始化
late AudioService _audioService;
@override
void didChangeDependencies() {
super.didChangeDependencies();
// ✅ 只在第一次或 service 变化时赋值
_audioService = context.watch<AudioService>();
}
String _formatDuration(Duration d) { String _formatDuration(Duration d) {
if (d.inMilliseconds < 0) return '00:00';
final minutes = d.inMinutes; final minutes = d.inMinutes;
final seconds = d.inSeconds % 60; final seconds = d.inSeconds % 60;
return '${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}'; return '${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
@@ -29,7 +20,6 @@ class _PlayerPageState extends State<PlayerPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// ✅ 使用 watch 实时获取状态
final service = context.watch<AudioService>(); final service = context.watch<AudioService>();
final song = service.currentSong; final song = service.currentSong;
@@ -45,9 +35,9 @@ class _PlayerPageState extends State<PlayerPage> {
); );
} }
final isPlaying = service.isPlaying;
final position = service.position; final position = service.position;
final duration = service.duration; final duration = service.duration;
final isPlaying = service.isPlaying;
final progress = duration.inMilliseconds > 0 final progress = duration.inMilliseconds > 0
? position.inMilliseconds / duration.inMilliseconds ? position.inMilliseconds / duration.inMilliseconds
: 0.0; : 0.0;
@@ -61,6 +51,15 @@ class _PlayerPageState extends State<PlayerPage> {
icon: const Icon(Icons.arrow_back_ios_new, color: Colors.white), icon: const Icon(Icons.arrow_back_ios_new, color: Colors.white),
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(context),
), ),
title: const Text(
'正在播放',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
centerTitle: true,
actions: [ actions: [
IconButton( IconButton(
icon: const Icon(Icons.more_vert, color: Colors.white54), icon: const Icon(Icons.more_vert, color: Colors.white54),
@@ -73,9 +72,10 @@ class _PlayerPageState extends State<PlayerPage> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
// ---- 封面占位 ----
Container( Container(
width: 280, width: 240,
height: 280, height: 240,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
color: const Color(0xFF2A3332), color: const Color(0xFF2A3332),
@@ -89,35 +89,43 @@ class _PlayerPageState extends State<PlayerPage> {
), ),
child: const Icon( child: const Icon(
Icons.music_note, Icons.music_note,
size: 80, size: 64,
color: Colors.white24, color: Colors.white24,
), ),
), ),
const SizedBox(height: 48), const SizedBox(height: 48),
// ---- 歌曲信息 ----
Column( Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Text( Text(
song.title, song.title,
style: const TextStyle( style: const TextStyle(
fontSize: 22, fontSize: 20,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.white, color: Colors.white,
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Text( Text(
song.artist, song.artist,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 15,
color: Colors.grey[400], color: Colors.grey[400],
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
], ],
), ),
const SizedBox(height: 40), const SizedBox(height: 40),
// ---- 进度条 ----
Column( Column(
children: [ children: [
Slider( Slider(
@@ -130,6 +138,8 @@ class _PlayerPageState extends State<PlayerPage> {
}, },
activeColor: const Color(0xFFB8D4D0), activeColor: const Color(0xFFB8D4D0),
inactiveColor: Colors.grey[800], inactiveColor: Colors.grey[800],
min: 0.0,
max: 1.0,
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -153,19 +163,21 @@ class _PlayerPageState extends State<PlayerPage> {
], ],
), ),
const SizedBox(height: 32), const SizedBox(height: 32),
// ---- 播放控制 ----
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
IconButton( IconButton(
onPressed: () {}, onPressed: () {},
icon: const Icon(Icons.skip_previous, size: 32), icon: const Icon(Icons.skip_previous, size: 28),
color: Colors.white60, color: Colors.white60,
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(12),
), ),
const SizedBox(width: 24), const SizedBox(width: 20),
Container( Container(
width: 64, width: 56,
height: 64, height: 56,
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0xFFB8D4D0), color: const Color(0xFFB8D4D0),
shape: BoxShape.circle, shape: BoxShape.circle,
@@ -174,7 +186,7 @@ class _PlayerPageState extends State<PlayerPage> {
icon: Icon( icon: Icon(
isPlaying ? Icons.pause : Icons.play_arrow, isPlaying ? Icons.pause : Icons.play_arrow,
color: Colors.black87, color: Colors.black87,
size: 32, size: 28,
), ),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: () { onPressed: () {
@@ -182,26 +194,16 @@ class _PlayerPageState extends State<PlayerPage> {
}, },
), ),
), ),
const SizedBox(width: 24), const SizedBox(width: 20),
IconButton( IconButton(
onPressed: () {}, onPressed: () {},
icon: const Icon(Icons.skip_next, size: 32), icon: const Icon(Icons.skip_next, size: 28),
color: Colors.white60, color: Colors.white60,
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(12),
),
],
),
const SizedBox(height: 32),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.volume_up_outlined),
color: Colors.white38,
), ),
], ],
), ),
const SizedBox(height: 16),
], ],
), ),
), ),
+17 -7
View File
@@ -72,14 +72,24 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
try { try {
final url = WebDAVService.instance.getFileUrl(file.path); final url = WebDAVService.instance.getFileUrl(file.path);
// ✅ 硬编码认证头(与 home_page 保持一致 // ✅ 动态获取认证头(从 SharedPreferences 读取
final testHeaders = { final headers = await WebDAVService.instance.getAuthHeaders();
'Authorization':
'Basic ' + base64Encode(utf8.encode('test-user-1:Lxh10020328?')), if (headers.isEmpty) {
}; print('⚠️ 未获取到认证头,请检查 WebDAV 登录状态');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('请先登录 WebDAV'),
backgroundColor: Colors.orange,
),
);
}
return;
}
print('🎵 [文件列表] 播放 URL: $url'); print('🎵 [文件列表] 播放 URL: $url');
print('📋 [文件列表] 认证头已设置'); print('📋 [文件列表] 认证头已设置: ${headers.keys}');
final song = Song( final song = Song(
id: file.path, id: file.path,
@@ -89,7 +99,7 @@ class _WebDAVFileListPageState extends State<WebDAVFileListPage> {
); );
context.read<AudioService>().playSong(song); context.read<AudioService>().playSong(song);
await PlaybackService().play(url, headers: testHeaders); await PlaybackService().play(url, headers: headers);
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(