现阶段通知中心播放暂停切换功能已实现,但是上下一曲功能暂时消失,需要后续优化,这个commit是snapshot
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// lib/audio/player_controller.dart
|
||||
import 'package:media_kit/media_kit.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user