播放页部分调整,播放链路已打通

This commit is contained in:
2026-08-17 23:29:19 +08:00
parent 7566700bed
commit e96da3fb04
2 changed files with 113 additions and 19 deletions
+98 -13
View File
@@ -11,6 +11,8 @@ class PlayerPage extends StatefulWidget {
}
class _PlayerPageState extends State<PlayerPage> {
double? _dragProgress; // 拖动时的临时进度
String _formatDuration(Duration d) {
if (d.inMilliseconds < 0) return '00:00';
final minutes = d.inMinutes;
@@ -38,10 +40,20 @@ class _PlayerPageState extends State<PlayerPage> {
final isPlaying = service.isPlaying;
final position = service.position;
final duration = service.duration;
final bufferedPosition = service.bufferedPosition;
final progress = duration.inMilliseconds > 0
? position.inMilliseconds / duration.inMilliseconds
: 0.0;
final bufferProgress = duration.inMilliseconds > 0
? (bufferedPosition.inMilliseconds / duration.inMilliseconds)
.clamp(0.0, 1.0)
: 0.0;
// 拖动时显示拖动的进度,否则显示实际播放进度
final displayProgress = _dragProgress ?? progress;
return Scaffold(
backgroundColor: const Color(0xFF0E1211),
appBar: AppBar(
@@ -125,22 +137,95 @@ class _PlayerPageState extends State<PlayerPage> {
),
const SizedBox(height: 40),
// ---- 进度条 ----
// ---- 双层进度条(视觉与交互分离) ----
Column(
children: [
Slider(
value: progress.clamp(0.0, 1.0),
onChanged: (value) {
final newPosition = Duration(
milliseconds: (value * duration.inMilliseconds).round(),
);
service.seekTo(newPosition);
},
activeColor: const Color(0xFFB8D4D0),
inactiveColor: Colors.grey[800],
min: 0.0,
max: 1.0,
SizedBox(
height: 20,
child: LayoutBuilder(
builder: (context, constraints) {
final width = constraints.maxWidth;
final bufferWidth =
width * bufferProgress.clamp(0.0, 1.0);
final progressWidth = width * progress.clamp(0.0, 1.0);
return Stack(
alignment: Alignment.centerLeft,
children: [
// ① 底层:整首歌曲(暗灰色)
Container(
width: width,
height: 4,
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: BorderRadius.circular(2),
),
),
// ② 缓冲层(深青色)
Container(
width: bufferWidth,
height: 4,
decoration: BoxDecoration(
color: const Color(0xFF4A7A7A),
borderRadius: BorderRadius.circular(2),
),
),
// ③ 播放进度层(亮青色)
Container(
width: progressWidth,
height: 4,
decoration: BoxDecoration(
color: const Color(0xFFB8D4D0),
borderRadius: BorderRadius.circular(2),
),
),
// ④ 交互层(只负责手势,不显示任何轨道)
Positioned.fill(
child: SliderTheme(
data: SliderTheme.of(context).copyWith(
trackHeight: 0,
activeTrackColor: Colors.transparent,
inactiveTrackColor: Colors.transparent,
thumbColor: Colors.transparent, // ✅ 完全隐藏小球
overlayColor: Colors.transparent,
thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 0,
),
),
child: Slider(
value: progress.clamp(0.0, 1.0),
min: 0.0,
max: 1.0,
onChanged: (value) {
// 拖动时只更新本地状态,不触发 seek
setState(() {
_dragProgress = value;
});
},
onChangeEnd: (value) {
final newPosition = Duration(
milliseconds:
(value * duration.inMilliseconds)
.round(),
);
service.seekTo(newPosition);
setState(() {
_dragProgress = null;
});
},
),
),
),
],
);
},
),
),
// 时间显示
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [