33 lines
540 B
Dart
33 lines
540 B
Dart
import 'package:media_kit/media_kit.dart';
|
|
|
|
class PlayerService {
|
|
static final PlayerService _instance = PlayerService._internal();
|
|
|
|
factory PlayerService() => _instance;
|
|
|
|
PlayerService._internal();
|
|
|
|
Player? _player;
|
|
|
|
Player get player {
|
|
return _player ??= Player();
|
|
}
|
|
|
|
void play(String url) {
|
|
player.open(Media(url));
|
|
}
|
|
|
|
void pause() => player.pause();
|
|
|
|
void resume() => player.play();
|
|
|
|
void stop() => player.stop();
|
|
|
|
void dispose() {
|
|
_player?.dispose();
|
|
_player = null;
|
|
}
|
|
|
|
// 状态监听...
|
|
}
|