33 lines
1.2 KiB
Dart
33 lines
1.2 KiB
Dart
// lib/audio/player_controller.dart
|
|
import '../services/playback_service.dart'; // ⭐ 修正路径
|
|
|
|
class PlayerController {
|
|
static final PlayerController _instance = PlayerController._internal();
|
|
factory PlayerController() => _instance;
|
|
PlayerController._internal();
|
|
|
|
final PlaybackService _playback = PlaybackService();
|
|
|
|
// ---- 状态流(只读) ----
|
|
Stream<bool> get playingStream => _playback.player.stream.playing;
|
|
Stream<Duration> get positionStream => _playback.player.stream.position;
|
|
Stream<Duration> get durationStream => _playback.player.stream.duration;
|
|
Stream<void> get completedStream => _playback.player.stream.completed;
|
|
|
|
// ---- 当前状态快照 ----
|
|
bool get isPlaying => _playback.player.state.playing;
|
|
Duration get position => _playback.player.state.position;
|
|
Duration get duration => _playback.player.state.duration;
|
|
|
|
// ---- 控制命令 ----
|
|
Future<void> play() => _playback.resume();
|
|
Future<void> pause() => _playback.pause();
|
|
Future<void> stop() => _playback.stop();
|
|
Future<void> seek(Duration position) => _playback.seek(position);
|
|
|
|
// ---- 加载歌曲 ----
|
|
void load(String url, {Map<String, String>? headers}) {
|
|
_playback.play(url, headers: headers);
|
|
}
|
|
}
|