mod: 增加视频类型、兼容live布局

This commit is contained in:
guozhigq
2023-08-16 21:35:50 +08:00
parent d764f00b8a
commit 767a82eb98
3 changed files with 46 additions and 21 deletions

View File

@ -13,7 +13,7 @@ class LiveRoomController extends GetxController {
// 静音状态
RxBool volumeOff = false.obs;
PlPlayerController plPlayerController =
PlPlayerController.getInstance(controlsEnabled: false);
PlPlayerController.getInstance(videoType: 'live');
// MeeduPlayerController meeduPlayerController = MeeduPlayerController(
// colorTheme: Theme.of(Get.context!).colorScheme.primary,

View File

@ -39,7 +39,7 @@ class PlPlayerController {
///
final PlPlayerDataStatus dataStatus = PlPlayerDataStatus();
bool controlsEnabled = true;
// bool controlsEnabled = false;
/// 响应数据
// 播放位置
@ -62,6 +62,8 @@ class PlPlayerController {
final Rx<bool> _doubleSpeedStatus = false.obs;
final Rx<bool> _controlsLock = false.obs;
final Rx<bool> _isFullScreen = false.obs;
// 默认投稿视频格式
static Rx<String> _videoType = 'archive'.obs;
final Rx<String> _direction = 'horizontal'.obs;
@ -188,9 +190,12 @@ class PlPlayerController {
Rx<int> get playerCount => _playerCount;
///
Rx<String> get videoType => _videoType;
// 添加一个私有构造函数
PlPlayerController._() {
controlsEnabled = controlsEnabled;
_videoType = videoType;
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
// if (status == PlayerStatus.playing) {
// WakelockPlus.enable();
@ -202,7 +207,7 @@ class PlPlayerController {
// 获取实例 传参
static PlPlayerController getInstance({
bool controlsEnabled = true,
String videoType = 'archive',
List<BoxFit> fits = const [
BoxFit.contain,
BoxFit.cover,
@ -215,6 +220,7 @@ class PlPlayerController {
// 如果实例尚未创建,则创建一个新实例
_instance ??= PlPlayerController._();
_instance!._playerCount.value += 1;
_videoType.value = videoType;
return _instance!;
}
@ -672,9 +678,18 @@ class PlPlayerController {
}
}
/// 设置长按倍速状态
/// 设置长按倍速状态 live模式下禁用
void setDoubleSpeedStatus(bool val) {
if (videoType.value == 'live') {
return;
}
_doubleSpeedStatus.value = val;
double currentSpeed = playbackSpeed;
if (val) {
setPlaybackSpeed(currentSpeed * 2);
} else {
setPlaybackSpeed(currentSpeed / 2);
}
}
/// 关闭控制栏

View File

@ -262,7 +262,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
),
/// 长按倍速
/// 长按倍速 toast
Obx(
() => Align(
alignment: Alignment.topCenter,
@ -301,7 +301,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
),
/// 时间进度
/// 时间进度 toast
Obx(
() => Align(
alignment: Alignment.topCenter,
@ -482,6 +482,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_.controls = !_.showControls.value;
},
onDoubleTapDown: (details) {
// live模式下禁用
if (_.videoType.value == 'live') {
return;
}
final totalWidth = MediaQuery.of(context).size.width;
final tapPosition = details.localPosition.dx;
final sectionWidth = totalWidth / 3;
@ -501,17 +505,17 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
},
onLongPressStart: (detail) {
feedBack();
double currentSpeed = _.playbackSpeed;
_.setDoubleSpeedStatus(true);
_.setPlaybackSpeed(currentSpeed * 2);
},
onLongPressEnd: (details) {
double currentSpeed = _.playbackSpeed;
_.setDoubleSpeedStatus(false);
_.setPlaybackSpeed(currentSpeed / 2);
},
// 水平位置 快进
/// 水平位置 快进 live模式下禁用
onHorizontalDragUpdate: (DragUpdateDetails details) {
if (_.videoType.value == 'live') {
return;
}
final tapPosition = details.localPosition.dx;
int curSliderPosition = _.sliderPosition.value.inSeconds;
late int result;
@ -530,6 +534,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_initTapPositoin = tapPosition;
},
onHorizontalDragEnd: (DragEndDetails details) {
if (_.videoType.value == 'live') {
return;
}
_.onChangedSliderEnd();
_.seekTo(_.sliderPosition.value);
},
@ -562,8 +569,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_distance = 0.0;
}
_distance = dy;
// triggerFullScreen();
} else {
// 右边区域 👈
final volume = _volumeValue - delta / 100.0;
@ -576,9 +581,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
// 头部、底部控制条
if (_.controlsEnabled)
Obx(
() => Column(
Obx(
() => Visibility(
visible: _.videoType.value != 'live',
child: Column(
children: [
if (widget.headerControl != null)
ClipRect(
@ -605,7 +611,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
],
),
),
// 进度条
),
/// 进度条 live模式下禁用
Obx(
() {
final int value = _.sliderPosition.value.inSeconds;
@ -658,9 +666,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
// 锁
if (_.controlsEnabled)
Obx(
() => Align(
Obx(
() => Visibility(
visible: _.videoType.value != 'live',
child: Align(
alignment: Alignment.centerLeft,
child: FractionalTranslation(
translation: const Offset(0.5, 0.0),
@ -680,6 +689,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
),
),
),
//
Obx(() {
if (_.dataStatus.loading || _.isBuffering.value) {