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