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; RxBool volumeOff = false.obs;
PlPlayerController plPlayerController = PlPlayerController plPlayerController =
PlPlayerController.getInstance(controlsEnabled: false); PlPlayerController.getInstance(videoType: 'live');
// MeeduPlayerController meeduPlayerController = MeeduPlayerController( // MeeduPlayerController meeduPlayerController = MeeduPlayerController(
// colorTheme: Theme.of(Get.context!).colorScheme.primary, // colorTheme: Theme.of(Get.context!).colorScheme.primary,

View File

@ -39,7 +39,7 @@ class PlPlayerController {
/// ///
final PlPlayerDataStatus dataStatus = PlPlayerDataStatus(); 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> _doubleSpeedStatus = false.obs;
final Rx<bool> _controlsLock = false.obs; final Rx<bool> _controlsLock = false.obs;
final Rx<bool> _isFullScreen = false.obs; final Rx<bool> _isFullScreen = false.obs;
// 默认投稿视频格式
static Rx<String> _videoType = 'archive'.obs;
final Rx<String> _direction = 'horizontal'.obs; final Rx<String> _direction = 'horizontal'.obs;
@ -188,9 +190,12 @@ class PlPlayerController {
Rx<int> get playerCount => _playerCount; Rx<int> get playerCount => _playerCount;
///
Rx<String> get videoType => _videoType;
// 添加一个私有构造函数 // 添加一个私有构造函数
PlPlayerController._() { PlPlayerController._() {
controlsEnabled = controlsEnabled; _videoType = videoType;
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
// if (status == PlayerStatus.playing) { // if (status == PlayerStatus.playing) {
// WakelockPlus.enable(); // WakelockPlus.enable();
@ -202,7 +207,7 @@ class PlPlayerController {
// 获取实例 传参 // 获取实例 传参
static PlPlayerController getInstance({ static PlPlayerController getInstance({
bool controlsEnabled = true, String videoType = 'archive',
List<BoxFit> fits = const [ List<BoxFit> fits = const [
BoxFit.contain, BoxFit.contain,
BoxFit.cover, BoxFit.cover,
@ -215,6 +220,7 @@ class PlPlayerController {
// 如果实例尚未创建,则创建一个新实例 // 如果实例尚未创建,则创建一个新实例
_instance ??= PlPlayerController._(); _instance ??= PlPlayerController._();
_instance!._playerCount.value += 1; _instance!._playerCount.value += 1;
_videoType.value = videoType;
return _instance!; return _instance!;
} }
@ -672,9 +678,18 @@ class PlPlayerController {
} }
} }
/// 设置长按倍速状态 /// 设置长按倍速状态 live模式下禁用
void setDoubleSpeedStatus(bool val) { void setDoubleSpeedStatus(bool val) {
if (videoType.value == 'live') {
return;
}
_doubleSpeedStatus.value = val; _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( Obx(
() => Align( () => Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
@ -301,7 +301,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
), ),
/// 时间进度 /// 时间进度 toast
Obx( Obx(
() => Align( () => Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
@ -482,6 +482,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_.controls = !_.showControls.value; _.controls = !_.showControls.value;
}, },
onDoubleTapDown: (details) { onDoubleTapDown: (details) {
// live模式下禁用
if (_.videoType.value == 'live') {
return;
}
final totalWidth = MediaQuery.of(context).size.width; final totalWidth = MediaQuery.of(context).size.width;
final tapPosition = details.localPosition.dx; final tapPosition = details.localPosition.dx;
final sectionWidth = totalWidth / 3; final sectionWidth = totalWidth / 3;
@ -501,17 +505,17 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
}, },
onLongPressStart: (detail) { onLongPressStart: (detail) {
feedBack(); feedBack();
double currentSpeed = _.playbackSpeed;
_.setDoubleSpeedStatus(true); _.setDoubleSpeedStatus(true);
_.setPlaybackSpeed(currentSpeed * 2);
}, },
onLongPressEnd: (details) { onLongPressEnd: (details) {
double currentSpeed = _.playbackSpeed;
_.setDoubleSpeedStatus(false); _.setDoubleSpeedStatus(false);
_.setPlaybackSpeed(currentSpeed / 2);
}, },
// 水平位置 快进
/// 水平位置 快进 live模式下禁用
onHorizontalDragUpdate: (DragUpdateDetails details) { onHorizontalDragUpdate: (DragUpdateDetails details) {
if (_.videoType.value == 'live') {
return;
}
final tapPosition = details.localPosition.dx; final tapPosition = details.localPosition.dx;
int curSliderPosition = _.sliderPosition.value.inSeconds; int curSliderPosition = _.sliderPosition.value.inSeconds;
late int result; late int result;
@ -530,6 +534,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_initTapPositoin = tapPosition; _initTapPositoin = tapPosition;
}, },
onHorizontalDragEnd: (DragEndDetails details) { onHorizontalDragEnd: (DragEndDetails details) {
if (_.videoType.value == 'live') {
return;
}
_.onChangedSliderEnd(); _.onChangedSliderEnd();
_.seekTo(_.sliderPosition.value); _.seekTo(_.sliderPosition.value);
}, },
@ -562,8 +569,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_distance = 0.0; _distance = 0.0;
} }
_distance = dy; _distance = dy;
// triggerFullScreen();
} else { } else {
// 右边区域 👈 // 右边区域 👈
final volume = _volumeValue - delta / 100.0; final volume = _volumeValue - delta / 100.0;
@ -576,9 +581,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
// 头部、底部控制条 // 头部、底部控制条
if (_.controlsEnabled) Obx(
Obx( () => Visibility(
() => Column( visible: _.videoType.value != 'live',
child: Column(
children: [ children: [
if (widget.headerControl != null) if (widget.headerControl != null)
ClipRect( ClipRect(
@ -605,7 +611,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
], ],
), ),
), ),
// 进度条 ),
/// 进度条 live模式下禁用
Obx( Obx(
() { () {
final int value = _.sliderPosition.value.inSeconds; final int value = _.sliderPosition.value.inSeconds;
@ -658,9 +666,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
// 锁 // 锁
if (_.controlsEnabled) Obx(
Obx( () => Visibility(
() => Align( visible: _.videoType.value != 'live',
child: Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: FractionalTranslation( child: FractionalTranslation(
translation: const Offset(0.5, 0.0), translation: const Offset(0.5, 0.0),
@ -680,6 +689,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
), ),
), ),
),
// //
Obx(() { Obx(() {
if (_.dataStatus.loading || _.isBuffering.value) { if (_.dataStatus.loading || _.isBuffering.value) {