opt: 播放器单例
This commit is contained in:
@ -17,8 +17,7 @@ class LiveRoomController extends GetxController {
|
||||
double volume = 0.0;
|
||||
// 静音状态
|
||||
RxBool volumeOff = false.obs;
|
||||
PlPlayerController plPlayerController =
|
||||
PlPlayerController.getInstance(videoType: 'live');
|
||||
PlPlayerController plPlayerController = PlPlayerController(videoType: 'live');
|
||||
Rx<RoomInfoH5Model> roomInfoH5 = RoomInfoH5Model().obs;
|
||||
late bool enableCDN;
|
||||
late int currentQn;
|
||||
|
@ -74,7 +74,7 @@ class VideoDetailController extends GetxController
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
RxString bgCover = ''.obs;
|
||||
RxString cover = ''.obs;
|
||||
PlPlayerController plPlayerController = PlPlayerController.getInstance();
|
||||
PlPlayerController plPlayerController = PlPlayerController();
|
||||
|
||||
late VideoItem firstVideo;
|
||||
late AudioItem firstAudio;
|
||||
|
@ -123,6 +123,7 @@ class PlPlayerController {
|
||||
PreferredSizeWidget? bottomControl;
|
||||
Widget? danmuWidget;
|
||||
late RxList subtitles;
|
||||
String videoType = 'archive';
|
||||
|
||||
/// 数据加载监听
|
||||
Stream<DataStatus> get onDataStatusChanged => dataStatus.status.stream;
|
||||
@ -220,7 +221,7 @@ class PlPlayerController {
|
||||
Rx<int> get playerCount => _playerCount;
|
||||
|
||||
///
|
||||
Rx<String> get videoType => _videoType;
|
||||
// Rx<String> get videoType => _videoType;
|
||||
|
||||
/// 弹幕开关
|
||||
Rx<bool> isOpenDanmu = false.obs;
|
||||
@ -274,8 +275,7 @@ class PlPlayerController {
|
||||
}
|
||||
|
||||
// 添加一个私有构造函数
|
||||
PlPlayerController._() {
|
||||
_videoType = videoType;
|
||||
PlPlayerController._internal(this.videoType) {
|
||||
isOpenDanmu.value =
|
||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||
blockTypes =
|
||||
@ -330,11 +330,11 @@ class PlPlayerController {
|
||||
}
|
||||
|
||||
// 获取实例 传参
|
||||
static PlPlayerController getInstance({
|
||||
factory PlPlayerController({
|
||||
String videoType = 'archive',
|
||||
}) {
|
||||
// 如果实例尚未创建,则创建一个新实例
|
||||
_instance ??= PlPlayerController._();
|
||||
_instance ??= PlPlayerController._internal(videoType);
|
||||
if (videoType != 'none') {
|
||||
_instance!._playerCount.value += 1;
|
||||
_videoType.value = videoType;
|
||||
@ -443,7 +443,7 @@ class PlPlayerController {
|
||||
configuration: PlayerConfiguration(
|
||||
// 默认缓存 5M 大小
|
||||
bufferSize:
|
||||
videoType.value == 'live' ? 32 * 1024 * 1024 : 5 * 1024 * 1024,
|
||||
videoType == 'live' ? 32 * 1024 * 1024 : 5 * 1024 * 1024,
|
||||
),
|
||||
);
|
||||
|
||||
@ -541,7 +541,7 @@ class PlPlayerController {
|
||||
}
|
||||
|
||||
/// 设置倍速
|
||||
if (videoType.value == 'live') {
|
||||
if (videoType == 'live') {
|
||||
await setPlaybackSpeed(1.0);
|
||||
} else {
|
||||
if (_playbackSpeed.value != 1.0) {
|
||||
@ -933,7 +933,7 @@ class PlPlayerController {
|
||||
|
||||
/// 设置长按倍速状态 live模式下禁用
|
||||
void setDoubleSpeedStatus(bool val) {
|
||||
if (videoType.value == 'live') {
|
||||
if (videoType == 'live') {
|
||||
return;
|
||||
}
|
||||
if (controlsLock.value) {
|
||||
@ -1015,7 +1015,7 @@ class PlPlayerController {
|
||||
if (!_enableHeart) {
|
||||
return false;
|
||||
}
|
||||
if (videoType.value == 'live') {
|
||||
if (videoType == 'live') {
|
||||
return;
|
||||
}
|
||||
// 播放状态变化时,更新
|
||||
@ -1114,7 +1114,6 @@ class PlPlayerController {
|
||||
// _buffered.close();
|
||||
// _showControls.close();
|
||||
// _controlsLock.close();
|
||||
|
||||
// playerStatus.status.close();
|
||||
// dataStatus.status.close();
|
||||
|
||||
|
@ -652,7 +652,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
},
|
||||
onDoubleTapDown: (TapDownDetails details) {
|
||||
// live模式下禁用 锁定时🔒禁用
|
||||
if (_.videoType.value == 'live' || _.controlsLock.value) {
|
||||
if (_.videoType == 'live' || _.controlsLock.value) {
|
||||
return;
|
||||
}
|
||||
final double totalWidth = MediaQuery.sizeOf(context).width;
|
||||
@ -679,7 +679,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
/// 水平位置 快进 live模式下禁用
|
||||
onHorizontalDragUpdate: (DragUpdateDetails details) {
|
||||
// live模式下禁用 锁定时🔒禁用
|
||||
if (_.videoType.value == 'live' || _.controlsLock.value) {
|
||||
if (_.videoType == 'live' || _.controlsLock.value) {
|
||||
return;
|
||||
}
|
||||
// final double tapPosition = details.localPosition.dx;
|
||||
@ -695,7 +695,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
_.onChangedSliderStart();
|
||||
},
|
||||
onHorizontalDragEnd: (DragEndDetails details) {
|
||||
if (_.videoType.value == 'live' || _.controlsLock.value) {
|
||||
if (_.videoType == 'live' || _.controlsLock.value) {
|
||||
return;
|
||||
}
|
||||
_.onChangedSliderEnd();
|
||||
@ -826,7 +826,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
if (_.videoType.value == 'live') {
|
||||
if (_.videoType == 'live') {
|
||||
return const SizedBox();
|
||||
}
|
||||
if (value > max || max <= 0) {
|
||||
@ -879,7 +879,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
// 锁
|
||||
Obx(
|
||||
() => Visibility(
|
||||
visible: _.videoType.value != 'live' && _.isFullScreen.value,
|
||||
visible: _.videoType != 'live' && _.isFullScreen.value,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: FractionalTranslation(
|
||||
|
@ -26,7 +26,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
|
||||
static final List<MediaItem> _item = [];
|
||||
Box setting = GStrorage.setting;
|
||||
bool enableBackgroundPlay = false;
|
||||
PlPlayerController player = PlPlayerController.getInstance();
|
||||
PlPlayerController player = PlPlayerController();
|
||||
|
||||
VideoPlayerServiceHandler() {
|
||||
revalidateSetting();
|
||||
|
@ -18,7 +18,7 @@ class AudioSessionHandler {
|
||||
session.configure(const AudioSessionConfiguration.music());
|
||||
|
||||
session.interruptionEventStream.listen((event) {
|
||||
final player = PlPlayerController.getInstance(videoType: 'none');
|
||||
final player = PlPlayerController(videoType: 'none');
|
||||
if (event.begin) {
|
||||
if (!player.playerStatus.playing) return;
|
||||
switch (event.type) {
|
||||
@ -51,7 +51,7 @@ class AudioSessionHandler {
|
||||
|
||||
// 耳机拔出暂停
|
||||
session.becomingNoisyEventStream.listen((_) {
|
||||
final player = PlPlayerController.getInstance(videoType: 'none');
|
||||
final player = PlPlayerController(videoType: 'none');
|
||||
if (player.playerStatus.playing) {
|
||||
player.pause();
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class ShutdownTimerService {
|
||||
return;
|
||||
}
|
||||
PlPlayerController plPlayerController =
|
||||
PlPlayerController.getInstance(videoType: 'none');
|
||||
PlPlayerController(videoType: 'none');
|
||||
if (!exitApp && !waitForPlayingCompleted) {
|
||||
if (!plPlayerController.playerStatus.playing) {
|
||||
//仅提示用户
|
||||
@ -124,7 +124,7 @@ class ShutdownTimerService {
|
||||
} else {
|
||||
//暂停播放
|
||||
PlPlayerController plPlayerController =
|
||||
PlPlayerController.getInstance(videoType: 'none');
|
||||
PlPlayerController(videoType: 'none');
|
||||
if (plPlayerController.playerStatus.playing) {
|
||||
plPlayerController.pause();
|
||||
waitForPlayingCompleted = true;
|
||||
|
Reference in New Issue
Block a user