mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-19 08:36:17 +08:00
opt type
opt ua opt subtitle opt playertype Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -93,9 +93,9 @@ class PlPlayerController {
|
||||
final RxBool _controlsLock = false.obs;
|
||||
final RxBool _isFullScreen = false.obs;
|
||||
// 默认投稿视频格式
|
||||
static final RxString _videoType = 'archive'.obs;
|
||||
bool _isLive = false;
|
||||
|
||||
final RxString _direction = 'horizontal'.obs;
|
||||
bool _isVertical = false;
|
||||
|
||||
final Rx<BoxFit> _videoFit = Rx(BoxFit.contain);
|
||||
late StreamSubscription<DataStatus> _dataListenerForVideoFit;
|
||||
@@ -241,12 +241,12 @@ class PlPlayerController {
|
||||
RxBool get isFullScreen => _isFullScreen;
|
||||
|
||||
/// 全屏方向
|
||||
RxString get direction => _direction;
|
||||
bool get isVertical => _isVertical;
|
||||
|
||||
RxInt get playerCount => _playerCount;
|
||||
|
||||
///
|
||||
RxString get videoType => _videoType;
|
||||
bool get isLive => _isLive;
|
||||
|
||||
/// 弹幕开关
|
||||
RxBool enableShowDanmaku = Pref.enableShowDanmaku.obs;
|
||||
@@ -467,7 +467,8 @@ class PlPlayerController {
|
||||
Box video = GStorage.video;
|
||||
|
||||
// 添加一个私有构造函数
|
||||
PlPlayerController._() {
|
||||
PlPlayerController._({bool isLive = false}) {
|
||||
_isLive = isLive;
|
||||
if (!Accounts.get(AccountType.heartbeat).isLogin || Pref.historyPause) {
|
||||
enableHeart = false;
|
||||
}
|
||||
@@ -492,13 +493,10 @@ class PlPlayerController {
|
||||
}
|
||||
|
||||
// 获取实例 传参
|
||||
static PlPlayerController getInstance({
|
||||
String videoType = 'archive',
|
||||
}) {
|
||||
static PlPlayerController getInstance({bool isLive = false}) {
|
||||
// 如果实例尚未创建,则创建一个新实例
|
||||
_instance ??= PlPlayerController._();
|
||||
_instance ??= PlPlayerController._(isLive: isLive);
|
||||
_instance!._playerCount.value += 1;
|
||||
_videoType.value = videoType;
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
@@ -520,7 +518,7 @@ class PlPlayerController {
|
||||
int? height,
|
||||
Duration? duration,
|
||||
// 方向
|
||||
String? direction,
|
||||
bool? isVertical,
|
||||
// 记录历史记录
|
||||
String bvid = '',
|
||||
int cid = 0,
|
||||
@@ -544,7 +542,7 @@ class PlPlayerController {
|
||||
// 初始化数据加载状态
|
||||
dataStatus.status.value = DataStatus.loading;
|
||||
// 初始化全屏方向
|
||||
_direction.value = direction ?? 'horizontal';
|
||||
_isVertical = isVertical ?? false;
|
||||
_bvid = bvid;
|
||||
_cid = cid;
|
||||
_epid = epid;
|
||||
@@ -697,12 +695,8 @@ class PlPlayerController {
|
||||
configuration: PlayerConfiguration(
|
||||
// 默认缓冲 4M 大小
|
||||
bufferSize: Pref.expandBuffer
|
||||
? (videoType.value == 'live'
|
||||
? 64 * 1024 * 1024
|
||||
: 32 * 1024 * 1024)
|
||||
: (videoType.value == 'live'
|
||||
? 16 * 1024 * 1024
|
||||
: 4 * 1024 * 1024),
|
||||
? (isLive ? 64 * 1024 * 1024 : 32 * 1024 * 1024)
|
||||
: (isLive ? 16 * 1024 * 1024 : 4 * 1024 * 1024),
|
||||
),
|
||||
);
|
||||
var pp = player.platform as NativePlayer;
|
||||
@@ -833,7 +827,7 @@ class PlPlayerController {
|
||||
Future<void> _initializePlayer() async {
|
||||
if (_instance == null) return;
|
||||
// 设置倍速
|
||||
if (videoType.value == 'live') {
|
||||
if (isLive) {
|
||||
await setPlaybackSpeed(1.0);
|
||||
} else {
|
||||
if (_videoPlayerController?.state.rate != _playbackSpeed.value) {
|
||||
@@ -891,7 +885,7 @@ class PlPlayerController {
|
||||
videoPlayerServiceHandler.onStatusChange(
|
||||
playerStatus.status.value,
|
||||
isBuffering.value,
|
||||
videoType.value == 'live',
|
||||
isLive,
|
||||
);
|
||||
|
||||
/// 触发回调事件
|
||||
@@ -941,12 +935,12 @@ class PlPlayerController {
|
||||
videoPlayerServiceHandler.onStatusChange(
|
||||
playerStatus.status.value,
|
||||
event,
|
||||
videoType.value == 'live',
|
||||
isLive,
|
||||
);
|
||||
}),
|
||||
videoPlayerController!.stream.error.listen((String event) {
|
||||
// 直播的错误提示没有参考价值,均不予显示
|
||||
if (videoType.value == 'live') return;
|
||||
if (isLive) return;
|
||||
if (event.startsWith("Failed to open https://") ||
|
||||
event.startsWith("Can not open external file https://") ||
|
||||
//tcp: ffurl_read returned 0xdfb9b0bb
|
||||
@@ -957,11 +951,12 @@ class PlPlayerController {
|
||||
const Duration(milliseconds: 10000),
|
||||
() {
|
||||
Future.delayed(const Duration(milliseconds: 3000), () async {
|
||||
if (kDebugMode) {
|
||||
debugPrint("isBuffering.value: ${isBuffering.value}");
|
||||
}
|
||||
if (kDebugMode)
|
||||
debugPrint("_buffered.value: ${_buffered.value}");
|
||||
// if (kDebugMode) {
|
||||
// debugPrint("isBuffering.value: ${isBuffering.value}");
|
||||
// }
|
||||
// if (kDebugMode) {
|
||||
// debugPrint("_buffered.value: ${_buffered.value}");
|
||||
// }
|
||||
if (isBuffering.value && _buffered.value == Duration.zero) {
|
||||
SmartDialog.showToast(
|
||||
'视频链接打开失败,重试中',
|
||||
@@ -998,7 +993,7 @@ class PlPlayerController {
|
||||
videoPlayerServiceHandler.onStatusChange(
|
||||
event,
|
||||
isBuffering.value,
|
||||
videoType.value == 'live',
|
||||
isLive,
|
||||
);
|
||||
}),
|
||||
onPositionChanged.listen((Duration event) {
|
||||
@@ -1286,7 +1281,7 @@ class PlPlayerController {
|
||||
});
|
||||
}
|
||||
// fill不应该在竖屏视频生效
|
||||
} else if (attr == BoxFit.fill && direction.value == 'vertical') {
|
||||
} else if (attr == BoxFit.fill && isVertical) {
|
||||
attr = BoxFit.contain;
|
||||
}
|
||||
_videoFit.value = attr;
|
||||
@@ -1312,7 +1307,7 @@ class PlPlayerController {
|
||||
|
||||
/// 设置长按倍速状态 live模式下禁用
|
||||
Future<void> setLongPressStatus(bool val) async {
|
||||
if (videoType.value == 'live') {
|
||||
if (isLive) {
|
||||
return;
|
||||
}
|
||||
if (controlsLock.value) {
|
||||
@@ -1376,10 +1371,9 @@ class PlPlayerController {
|
||||
return;
|
||||
}
|
||||
if (mode == FullScreenMode.vertical ||
|
||||
(mode == FullScreenMode.auto && direction.value == 'vertical') ||
|
||||
(mode == FullScreenMode.auto && isVertical) ||
|
||||
(mode == FullScreenMode.ratio &&
|
||||
(Get.height / Get.width < 1.25 ||
|
||||
direction.value == 'vertical'))) {
|
||||
(Get.height / Get.width < 1.25 || isVertical))) {
|
||||
await verticalScreenForTwoSeconds();
|
||||
} else {
|
||||
await landScape();
|
||||
@@ -1445,7 +1439,7 @@ class PlPlayerController {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (videoType.value == 'live') {
|
||||
if (isLive) {
|
||||
return;
|
||||
}
|
||||
bool isComplete =
|
||||
@@ -1512,9 +1506,9 @@ class PlPlayerController {
|
||||
..put(SettingBoxKey.subtitleFontWeight, subtitleFontWeight);
|
||||
}
|
||||
|
||||
Future<void> dispose({String type = 'single'}) async {
|
||||
Future<void> dispose() async {
|
||||
// 每次减1,最后销毁
|
||||
if (type == 'single' && playerCount.value > 1) {
|
||||
if (playerCount.value > 1) {
|
||||
_playerCount.value -= 1;
|
||||
_heartDuration = 0;
|
||||
if (!Get.previousRoute.startsWith('/video')) {
|
||||
|
||||
1
lib/plugin/pl_player/models/double_tap_type.dart
Normal file
1
lib/plugin/pl_player/models/double_tap_type.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum DoubleTapType { left, center, right }
|
||||
10
lib/plugin/pl_player/models/gesture_type.dart
Normal file
10
lib/plugin/pl_player/models/gesture_type.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
enum GestureType {
|
||||
left,
|
||||
center,
|
||||
right,
|
||||
horizontal,
|
||||
center_up,
|
||||
center_down,
|
||||
}
|
||||
@@ -16,8 +16,10 @@ import 'package:PiliPlus/pages/video/introduction/ugc/controller.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/controller.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/bottom_control_type.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/bottom_progress_behavior.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/double_tap_type.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/duration.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/gesture_type.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/utils.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/widgets/app_bar_ani.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/widgets/backward_seek.dart';
|
||||
@@ -110,7 +112,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
late final RxBool showRestoreScaleBtn = false.obs;
|
||||
|
||||
Offset _initialFocalPoint = Offset.zero;
|
||||
String? _gestureType;
|
||||
GestureType? _gestureType;
|
||||
//播放器放缩
|
||||
bool interacting = false;
|
||||
|
||||
@@ -138,20 +140,20 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
}
|
||||
|
||||
void doubleTapFuc(String type) {
|
||||
void doubleTapFuc(DoubleTapType type) {
|
||||
if (!plPlayerController.enableQuickDouble) {
|
||||
onDoubleTapCenter();
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case 'left':
|
||||
case DoubleTapType.left:
|
||||
// 双击左边区域 👈
|
||||
onDoubleTapSeekBackward();
|
||||
break;
|
||||
case 'center':
|
||||
case DoubleTapType.center:
|
||||
onDoubleTapCenter();
|
||||
break;
|
||||
case 'right':
|
||||
case DoubleTapType.right:
|
||||
// 双击右边区域 👈
|
||||
onDoubleTapSeekForward();
|
||||
break;
|
||||
@@ -770,7 +772,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
if (cumulativeDelta.distance < 1) return;
|
||||
if (cumulativeDelta.dx.abs() >
|
||||
3 * cumulativeDelta.dy.abs()) {
|
||||
_gestureType = 'horizontal';
|
||||
_gestureType = GestureType.horizontal;
|
||||
} else if (cumulativeDelta.dy.abs() >
|
||||
3 * cumulativeDelta.dx.abs()) {
|
||||
if (!plPlayerController.enableSlideVolumeBrightness &&
|
||||
@@ -787,19 +789,19 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
return;
|
||||
}
|
||||
// 左边区域
|
||||
_gestureType = 'left';
|
||||
_gestureType = GestureType.left;
|
||||
} else if (tapPosition < sectionWidth * 2) {
|
||||
if (!plPlayerController.enableSlideFS) {
|
||||
return;
|
||||
}
|
||||
// 全屏
|
||||
_gestureType = 'center';
|
||||
_gestureType = GestureType.center;
|
||||
} else {
|
||||
if (!plPlayerController.enableSlideVolumeBrightness) {
|
||||
return;
|
||||
}
|
||||
// 右边区域
|
||||
_gestureType = 'right';
|
||||
_gestureType = GestureType.right;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
@@ -808,9 +810,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
|
||||
Offset delta = details.focalPointDelta;
|
||||
|
||||
if (_gestureType == 'horizontal') {
|
||||
if (_gestureType == GestureType.horizontal) {
|
||||
// live模式下禁用
|
||||
if (plPlayerController.videoType.value == 'live') return;
|
||||
if (plPlayerController.isLive) return;
|
||||
|
||||
final int curSliderPosition =
|
||||
plPlayerController.sliderPosition.value.inMilliseconds;
|
||||
@@ -884,14 +886,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
} else if (_gestureType == 'left') {
|
||||
} else if (_gestureType == GestureType.left) {
|
||||
// 左边区域 👈
|
||||
final double level = maxHeight * 3;
|
||||
final double brightness =
|
||||
_brightnessValue.value - delta.dy / level;
|
||||
final double result = brightness.clamp(0.0, 1.0);
|
||||
setBrightness(result);
|
||||
} else if (_gestureType == 'center') {
|
||||
} else if (_gestureType == GestureType.center) {
|
||||
// 全屏
|
||||
const double threshold = 2.5; // 滑动阈值
|
||||
double cumulativeDy =
|
||||
@@ -902,7 +904,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
|
||||
if (cumulativeDy > threshold) {
|
||||
_gestureType = 'center_down';
|
||||
_gestureType = GestureType.center_down;
|
||||
if (isFullScreen ^
|
||||
plPlayerController.fullScreenGestureReverse) {
|
||||
fullScreenTrigger(
|
||||
@@ -911,7 +913,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
// if (kDebugMode) debugPrint('center_down:$cumulativeDy');
|
||||
} else if (cumulativeDy < -threshold) {
|
||||
_gestureType = 'center_up';
|
||||
_gestureType = GestureType.center_up;
|
||||
if (!isFullScreen ^
|
||||
plPlayerController.fullScreenGestureReverse) {
|
||||
fullScreenTrigger(
|
||||
@@ -920,7 +922,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
// if (kDebugMode) debugPrint('center_up:$cumulativeDy');
|
||||
}
|
||||
} else if (_gestureType == 'right') {
|
||||
} else if (_gestureType == GestureType.right) {
|
||||
// 右边区域
|
||||
final double level = maxHeight * 0.5;
|
||||
EasyThrottle.throttle(
|
||||
@@ -975,25 +977,25 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
final double tapPosition = details.localPosition.dx;
|
||||
final double sectionWidth = maxWidth / 3;
|
||||
late String gestureType;
|
||||
late GestureType gestureType;
|
||||
if (tapPosition < sectionWidth) {
|
||||
if (!plPlayerController.enableSlideVolumeBrightness) {
|
||||
return;
|
||||
}
|
||||
// 左边区域
|
||||
gestureType = 'left';
|
||||
gestureType = GestureType.left;
|
||||
} else if (tapPosition < sectionWidth * 2) {
|
||||
if (!plPlayerController.enableSlideFS) {
|
||||
return;
|
||||
}
|
||||
// 全屏
|
||||
gestureType = 'center';
|
||||
gestureType = GestureType.center;
|
||||
} else {
|
||||
if (!plPlayerController.enableSlideVolumeBrightness) {
|
||||
return;
|
||||
}
|
||||
// 右边区域
|
||||
gestureType = 'right';
|
||||
gestureType = GestureType.right;
|
||||
}
|
||||
|
||||
if (_gestureType != null && _gestureType != gestureType) {
|
||||
@@ -1001,14 +1003,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
_gestureType = gestureType;
|
||||
|
||||
if (_gestureType == 'left') {
|
||||
if (_gestureType == GestureType.left) {
|
||||
// 左边区域 👈
|
||||
final double level = maxHeight * 3;
|
||||
final double brightness =
|
||||
_brightnessValue.value - details.delta.dy / level;
|
||||
final double result = brightness.clamp(0.0, 1.0);
|
||||
setBrightness(result);
|
||||
} else if (_gestureType == 'center') {
|
||||
} else if (_gestureType == GestureType.center) {
|
||||
// 全屏
|
||||
const double threshold = 2.5; // 滑动阈值
|
||||
double cumulativeDy =
|
||||
@@ -1019,7 +1021,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
|
||||
if (cumulativeDy > threshold) {
|
||||
_gestureType = 'center_down';
|
||||
_gestureType = GestureType.center_down;
|
||||
if (isFullScreen ^
|
||||
plPlayerController.fullScreenGestureReverse) {
|
||||
fullScreenTrigger(
|
||||
@@ -1028,7 +1030,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
// if (kDebugMode) debugPrint('center_down:$cumulativeDy');
|
||||
} else if (cumulativeDy < -threshold) {
|
||||
_gestureType = 'center_up';
|
||||
_gestureType = GestureType.center_up;
|
||||
if (!isFullScreen ^
|
||||
plPlayerController.fullScreenGestureReverse) {
|
||||
fullScreenTrigger(
|
||||
@@ -1037,7 +1039,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
// if (kDebugMode) debugPrint('center_up:$cumulativeDy');
|
||||
}
|
||||
} else if (_gestureType == 'right') {
|
||||
} else if (_gestureType == GestureType.right) {
|
||||
// 右边区域
|
||||
final double level = maxHeight * 0.5;
|
||||
EasyThrottle.throttle(
|
||||
@@ -1065,19 +1067,19 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
if (plPlayerController.controlsLock.value) {
|
||||
return;
|
||||
}
|
||||
if (plPlayerController.videoType.value == 'live') {
|
||||
doubleTapFuc('center');
|
||||
if (plPlayerController.isLive) {
|
||||
doubleTapFuc(DoubleTapType.center);
|
||||
return;
|
||||
}
|
||||
final double tapPosition = details.localPosition.dx;
|
||||
final double sectionWidth = maxWidth / 4;
|
||||
String type = 'left';
|
||||
DoubleTapType type;
|
||||
if (tapPosition < sectionWidth) {
|
||||
type = 'left';
|
||||
type = DoubleTapType.left;
|
||||
} else if (tapPosition < sectionWidth * 3) {
|
||||
type = 'center';
|
||||
type = DoubleTapType.center;
|
||||
} else {
|
||||
type = 'right';
|
||||
type = DoubleTapType.right;
|
||||
}
|
||||
doubleTapFuc(type);
|
||||
},
|
||||
@@ -1426,7 +1428,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
}
|
||||
|
||||
if (plPlayerController.videoType.value == 'live') {
|
||||
if (plPlayerController.isLive) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
@@ -1551,9 +1553,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
SafeArea(
|
||||
child: Obx(
|
||||
() => Visibility(
|
||||
visible:
|
||||
plPlayerController.videoType.value != 'live' &&
|
||||
isFullScreen,
|
||||
visible: !plPlayerController.isLive && isFullScreen,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: FractionalTranslation(
|
||||
@@ -1895,7 +1895,7 @@ Widget buildSeekPreviewWidget(PlPlayerController plPlayerController) {
|
||||
try {
|
||||
double scale =
|
||||
plPlayerController.isFullScreen.value &&
|
||||
plPlayerController.direction.value == 'horizontal'
|
||||
!plPlayerController.isVertical
|
||||
? 4
|
||||
: 2.5;
|
||||
// offset
|
||||
|
||||
Reference in New Issue
Block a user