Merge branch 'fix' into alpha

This commit is contained in:
guozhigq
2023-09-12 16:04:50 +08:00
3 changed files with 241 additions and 221 deletions

View File

@ -317,13 +317,15 @@ class VideoDetailController extends GetxController
closestNumber = 30280; closestNumber = 30280;
} }
firstAudio = audiosList.firstWhere((e) => e.id == closestNumber); firstAudio = audiosList.firstWhere((e) => e.id == closestNumber);
} else {
firstAudio = AudioItem();
} }
} catch (err) { } catch (err) {
firstAudio = audiosList.first; firstAudio = audiosList.isNotEmpty ? audiosList.first : AudioItem();
SmartDialog.showToast('firstAudio error: $err'); SmartDialog.showToast('firstAudio error: $err');
} }
audioUrl = firstAudio!.baseUrl ?? ''; audioUrl = firstAudio.baseUrl ?? '';
// //
if (firstAudio.id != null) { if (firstAudio.id != null) {
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!; currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;

View File

@ -820,6 +820,9 @@ class PlPlayerController {
builder: (context) => Dialog.fullscreen( builder: (context) => Dialog.fullscreen(
backgroundColor: Colors.black, backgroundColor: Colors.black,
child: SafeArea( child: SafeArea(
// 忽略手机安全区域
left: false,
right: false,
bottom: bottom:
direction.value == 'vertical' || mode == FullScreenMode.vertical direction.value == 'vertical' || mode == FullScreenMode.vertical
? true ? true

View File

@ -48,25 +48,26 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
with TickerProviderStateMixin { with TickerProviderStateMixin {
late AnimationController animationController; late AnimationController animationController;
late VideoController videoController; late VideoController videoController;
final PLVideoPlayerController _ctr = Get.put(PLVideoPlayerController());
bool _mountSeekBackwardButton = false; // bool _mountSeekBackwardButton = false;
bool _mountSeekForwardButton = false; // bool _mountSeekForwardButton = false;
bool _hideSeekBackwardButton = false; // bool _hideSeekBackwardButton = false;
bool _hideSeekForwardButton = false; // bool _hideSeekForwardButton = false;
double _brightnessValue = 0.0; // double _brightnessValue = 0.0;
bool _brightnessIndicator = false; // bool _brightnessIndicator = false;
Timer? _brightnessTimer; Timer? _brightnessTimer;
double _volumeValue = 0.0; // double _volumeValue = 0.0;
bool _volumeIndicator = false; // bool _volumeIndicator = false;
Timer? _volumeTimer; Timer? _volumeTimer;
double _distance = 0.0; double _distance = 0.0;
// 初始手指落下位置 // 初始手指落下位置
double _initTapPositoin = 0.0; double _initTapPositoin = 0.0;
bool _volumeInterceptEventStream = false; // bool _volumeInterceptEventStream = false;
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
late FullScreenMode mode; late FullScreenMode mode;
@ -75,15 +76,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late bool enableBackgroundPlay; late bool enableBackgroundPlay;
void onDoubleTapSeekBackward() { void onDoubleTapSeekBackward() {
setState(() { _ctr.onDoubleTapSeekBackward();
_mountSeekBackwardButton = true;
});
} }
void onDoubleTapSeekForward() { void onDoubleTapSeekForward() {
setState(() { _ctr.onDoubleTapSeekForward();
_mountSeekForwardButton = true;
});
} }
// 双击播放、暂停 // 双击播放、暂停
@ -135,12 +132,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Future.microtask(() async { Future.microtask(() async {
try { try {
FlutterVolumeController.showSystemUI = true; FlutterVolumeController.showSystemUI = true;
_volumeValue = (await FlutterVolumeController.getVolume())!; _ctr.volumeValue.value = (await FlutterVolumeController.getVolume())!;
FlutterVolumeController.addListener((value) { FlutterVolumeController.addListener((value) {
if (mounted && !_volumeInterceptEventStream) { if (mounted && !_ctr.volumeInterceptEventStream.value) {
setState(() { _ctr.volumeValue.value = value;
_volumeValue = value;
});
} }
}); });
} catch (_) {} } catch (_) {}
@ -148,12 +143,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Future.microtask(() async { Future.microtask(() async {
try { try {
_brightnessValue = await ScreenBrightness().current; _ctr.brightnessValue.value = await ScreenBrightness().current;
ScreenBrightness().onCurrentBrightnessChanged.listen((value) { ScreenBrightness().onCurrentBrightnessChanged.listen((value) {
if (mounted) { if (mounted) {
setState(() { _ctr.brightnessValue.value = value;
_brightnessValue = value;
});
} }
}); });
} catch (_) {} } catch (_) {}
@ -165,18 +158,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
FlutterVolumeController.showSystemUI = false; FlutterVolumeController.showSystemUI = false;
await FlutterVolumeController.setVolume(value); await FlutterVolumeController.setVolume(value);
} catch (_) {} } catch (_) {}
setState(() { _ctr.volumeValue.value = value;
_volumeValue = value; _ctr.volumeIndicator.value = true;
_volumeIndicator = true; _ctr.volumeInterceptEventStream.value = true;
_volumeInterceptEventStream = true;
});
_volumeTimer?.cancel(); _volumeTimer?.cancel();
_volumeTimer = Timer(const Duration(milliseconds: 200), () { _volumeTimer = Timer(const Duration(milliseconds: 200), () {
if (mounted) { if (mounted) {
setState(() { _ctr.volumeIndicator.value = false;
_volumeIndicator = false; _ctr.volumeInterceptEventStream.value = false;
_volumeInterceptEventStream = false;
});
} }
}); });
} }
@ -185,15 +174,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
try { try {
await ScreenBrightness().setScreenBrightness(value); await ScreenBrightness().setScreenBrightness(value);
} catch (_) {} } catch (_) {}
setState(() { _ctr.brightnessIndicator.value = true;
_brightnessIndicator = true;
});
_brightnessTimer?.cancel(); _brightnessTimer?.cancel();
_brightnessTimer = Timer(const Duration(milliseconds: 200), () { _brightnessTimer = Timer(const Duration(milliseconds: 200), () {
if (mounted) { if (mounted) {
setState(() { _ctr.brightnessIndicator.value = false;
_brightnessIndicator = false;
});
} }
}); });
widget.controller.brightness.value = value; widget.controller.brightness.value = value;
@ -322,11 +307,12 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
/// 音量🔊 控制条展示 /// 音量🔊 控制条展示
Align( Obx(
() => Align(
alignment: Alignment.center, alignment: Alignment.center,
child: AnimatedOpacity( child: AnimatedOpacity(
curve: Curves.easeInOut, curve: Curves.easeInOut,
opacity: _volumeIndicator ? 1.0 : 0.0, opacity: _ctr.volumeIndicator.value ? 1.0 : 0.0,
duration: const Duration(milliseconds: 150), duration: const Duration(milliseconds: 150),
child: Container( child: Container(
alignment: Alignment.center, alignment: Alignment.center,
@ -346,9 +332,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
width: 28.0, width: 28.0,
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Icon( child: Icon(
_volumeValue == 0.0 _ctr.volumeValue.value == 0.0
? Icons.volume_off ? Icons.volume_off
: _volumeValue < 0.5 : _ctr.volumeValue.value < 0.5
? Icons.volume_down ? Icons.volume_down
: Icons.volume_up, : Icons.volume_up,
color: const Color(0xFFFFFFFF), color: const Color(0xFFFFFFFF),
@ -357,7 +343,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
Expanded( Expanded(
child: Text( child: Text(
'${(_volumeValue * 100.0).round()}%', '${(_ctr.volumeValue.value * 100.0).round()}%',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
fontSize: 13.0, fontSize: 13.0,
@ -371,13 +357,15 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
), ),
), ),
),
/// 亮度🌞 控制条展示 /// 亮度🌞 控制条展示
Align( Obx(
() => Align(
alignment: Alignment.center, alignment: Alignment.center,
child: AnimatedOpacity( child: AnimatedOpacity(
curve: Curves.easeInOut, curve: Curves.easeInOut,
opacity: _brightnessIndicator ? 1.0 : 0.0, opacity: _ctr.brightnessIndicator.value ? 1.0 : 0.0,
duration: const Duration(milliseconds: 150), duration: const Duration(milliseconds: 150),
child: Container( child: Container(
alignment: Alignment.center, alignment: Alignment.center,
@ -397,9 +385,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
width: 28.0, width: 28.0,
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Icon( child: Icon(
_brightnessValue < 1.0 / 3.0 _ctr.brightnessValue.value < 1.0 / 3.0
? Icons.brightness_low ? Icons.brightness_low
: _brightnessValue < 2.0 / 3.0 : _ctr.brightnessValue.value < 2.0 / 3.0
? Icons.brightness_medium ? Icons.brightness_medium
: Icons.brightness_high, : Icons.brightness_high,
color: const Color(0xFFFFFFFF), color: const Color(0xFFFFFFFF),
@ -409,7 +397,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
const SizedBox(width: 2.0), const SizedBox(width: 2.0),
Expanded( Expanded(
child: Text( child: Text(
'${(_brightnessValue * 100.0).round()}%', '${(_ctr.brightnessValue.value * 100.0).round()}%',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
fontSize: 13.0, fontSize: 13.0,
@ -423,6 +411,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
), ),
), ),
),
// Obx(() { // Obx(() {
// if (_.buffered.value == Duration.zero) { // if (_.buffered.value == Duration.zero) {
@ -525,7 +514,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} }
if (tapPosition < sectionWidth) { if (tapPosition < sectionWidth) {
// 左边区域 👈 // 左边区域 👈
final brightness = _brightnessValue - delta / 100.0; final brightness = _ctr.brightnessValue.value - delta / 100.0;
final result = brightness.clamp(0.0, 1.0); final result = brightness.clamp(0.0, 1.0);
setBrightness(result); setBrightness(result);
} else if (tapPosition < sectionWidth * 2) { } else if (tapPosition < sectionWidth * 2) {
@ -548,7 +537,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_distance = dy; _distance = dy;
} else { } else {
// 右边区域 👈 // 右边区域 👈
final volume = _volumeValue - delta / 100.0; final volume = _ctr.volumeValue.value - delta / 100.0;
final result = volume.clamp(0.0, 1.0); final result = volume.clamp(0.0, 1.0);
setVolume(result); setVolume(result);
} }
@ -704,16 +693,20 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
}), }),
/// 点击 快进/快退 /// 点击 快进/快退
if (_mountSeekBackwardButton || _mountSeekForwardButton) Obx(
Positioned.fill( () => Visibility(
visible: _ctr.mountSeekBackwardButton.value ||
_ctr.mountSeekForwardButton.value,
child: Positioned.fill(
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: _mountSeekBackwardButton child: _ctr.mountSeekBackwardButton.value
? TweenAnimationBuilder<double>( ? TweenAnimationBuilder<double>(
tween: Tween<double>( tween: Tween<double>(
begin: 0.0, begin: 0.0,
end: _hideSeekBackwardButton ? 0.0 : 1.0, end:
_ctr.hideSeekBackwardButton.value ? 0.0 : 1.0,
), ),
duration: const Duration(milliseconds: 500), duration: const Duration(milliseconds: 500),
builder: (context, value, child) => Opacity( builder: (context, value, child) => Opacity(
@ -721,11 +714,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
child: child, child: child,
), ),
onEnd: () { onEnd: () {
if (_hideSeekBackwardButton) { if (_ctr.hideSeekBackwardButton.value) {
setState(() { _ctr.hideSeekBackwardButton.value = false;
_hideSeekBackwardButton = false; _ctr.mountSeekBackwardButton.value = false;
_mountSeekBackwardButton = false;
});
} }
}, },
child: BackwardSeekIndicator( child: BackwardSeekIndicator(
@ -733,9 +724,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
// _seekBarDeltaValueNotifier.value = -value; // _seekBarDeltaValueNotifier.value = -value;
}, },
onSubmitted: (value) { onSubmitted: (value) {
setState(() { _ctr.hideSeekBackwardButton.value = true;
_hideSeekBackwardButton = true;
});
Player player = Player player =
widget.controller.videoPlayerController!; widget.controller.videoPlayerController!;
var result = player.state.position - value; var result = player.state.position - value;
@ -756,11 +745,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
), ),
Expanded( Expanded(
child: _mountSeekForwardButton child: _ctr.mountSeekForwardButton.value
? TweenAnimationBuilder<double>( ? TweenAnimationBuilder<double>(
tween: Tween<double>( tween: Tween<double>(
begin: 0.0, begin: 0.0,
end: _hideSeekForwardButton ? 0.0 : 1.0, end: _ctr.hideSeekForwardButton.value ? 0.0 : 1.0,
), ),
duration: const Duration(milliseconds: 500), duration: const Duration(milliseconds: 500),
builder: (context, value, child) => Opacity( builder: (context, value, child) => Opacity(
@ -768,11 +757,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
child: child, child: child,
), ),
onEnd: () { onEnd: () {
if (_hideSeekForwardButton) { if (_ctr.hideSeekForwardButton.value) {
setState(() { _ctr.hideSeekForwardButton.value = false;
_hideSeekForwardButton = false; _ctr.mountSeekForwardButton.value = false;
_mountSeekForwardButton = false;
});
} }
}, },
child: ForwardSeekIndicator( child: ForwardSeekIndicator(
@ -780,9 +767,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
// _seekBarDeltaValueNotifier.value = value; // _seekBarDeltaValueNotifier.value = value;
}, },
onSubmitted: (value) { onSubmitted: (value) {
setState(() { _ctr.hideSeekForwardButton.value = true;
_hideSeekForwardButton = true;
});
Player player = Player player =
widget.controller.videoPlayerController!; widget.controller.videoPlayerController!;
var result = player.state.position + value; var result = player.state.position + value;
@ -800,7 +785,37 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
], ],
), ),
), ),
),
),
], ],
); );
} }
} }
class PLVideoPlayerController extends GetxController {
RxBool mountSeekBackwardButton = false.obs;
RxBool mountSeekForwardButton = false.obs;
RxBool hideSeekBackwardButton = false.obs;
RxBool hideSeekForwardButton = false.obs;
RxDouble brightnessValue = 0.0.obs;
RxBool brightnessIndicator = false.obs;
RxDouble volumeValue = 0.0.obs;
RxBool volumeIndicator = false.obs;
RxDouble distance = 0.0.obs;
// 初始手指落下位置
RxDouble initTapPositoin = 0.0.obs;
RxBool volumeInterceptEventStream = false.obs;
// 双击快进 展示样式
void onDoubleTapSeekForward() {
mountSeekForwardButton.value = true;
}
void onDoubleTapSeekBackward() {
mountSeekBackwardButton.value = true;
}
}