opt player keyboard event

opt triple

opt desktop pip

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-09-21 12:43:07 +08:00
parent 787be7ac11
commit 9f715ddd5b
8 changed files with 123 additions and 101 deletions

View File

@@ -20,7 +20,6 @@ import 'package:PiliPlus/pages/video/introduction/pgc/controller.dart';
import 'package:PiliPlus/pages/video/introduction/ugc/controller.dart';
import 'package:PiliPlus/pages/video/introduction/ugc/widgets/action_item.dart';
import 'package:PiliPlus/pages/video/introduction/ugc/widgets/menu_row.dart';
import 'package:PiliPlus/pages/video/introduction/ugc/widgets/triple_state.dart';
import 'package:PiliPlus/plugin/pl_player/controller.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart';
@@ -64,7 +63,7 @@ class HeaderControl extends StatefulWidget {
State<HeaderControl> createState() => HeaderControlState();
}
class HeaderControlState extends TripleState<HeaderControl> {
class HeaderControlState extends State<HeaderControl> {
late final PlPlayerController plPlayerController = widget.controller;
late final VideoDetailController videoDetailCtr = widget.videoDetailCtr;
late final PlayUrlModel videoInfo = videoDetailCtr.data;
@@ -74,7 +73,6 @@ class HeaderControlState extends TripleState<HeaderControl> {
String get heroTag => widget.heroTag;
late final UgcIntroController ugcIntroController;
late final PgcIntroController pgcIntroController;
@override
late CommonIntroController introController = videoDetailCtr.isUgc
? ugcIntroController
: pgcIntroController;
@@ -2289,16 +2287,16 @@ class HeaderControlState extends TripleState<HeaderControl> {
),
selectStatus: introController.hasLike.value,
semanticsLabel: '点赞',
animation: tripleAnimation,
animation: introController.tripleAnimation,
onStartTriple: () {
plPlayerController.tripling = true;
onStartTriple();
introController.onStartTriple();
},
onCancelTriple: ([bool isTap = false]) {
onCancelTriple: ([bool isTapUp = false]) {
plPlayerController
..tripling = false
..hideTaskControls();
onCancelTriple(isTap);
introController.onCancelTriple(isTapUp);
},
),
),
@@ -2329,7 +2327,7 @@ class HeaderControlState extends TripleState<HeaderControl> {
child: Obx(
() => ActionItem(
expand: false,
animation: tripleAnimation,
animation: introController.tripleAnimation,
icon: const Icon(
FontAwesomeIcons.b,
color: Colors.white,
@@ -2347,7 +2345,7 @@ class HeaderControlState extends TripleState<HeaderControl> {
child: Obx(
() => ActionItem(
expand: false,
animation: tripleAnimation,
animation: introController.tripleAnimation,
icon: const Icon(
FontAwesomeIcons.star,
color: Colors.white,

View File

@@ -55,8 +55,81 @@ class PlayerFocus extends StatelessWidget {
bool get isFullScreen => plPlayerController.isFullScreen.value;
bool get hasPlayer => plPlayerController.videoPlayerController != null;
void _setVolume({required bool isIncrease}) {
final volume = isIncrease
? math.min(1.0, plPlayerController.volume.value + 0.1)
: math.max(0.0, plPlayerController.volume.value - 0.1);
plPlayerController.setVolume(volume);
}
void _updateVolume(KeyEvent event, {required bool isIncrease}) {
if (event is KeyDownEvent) {
if (hasPlayer) {
plPlayerController
..cancelLongPressTimer()
..longPressTimer ??= Timer.periodic(
const Duration(milliseconds: 200),
(_) => _setVolume(isIncrease: isIncrease),
);
}
} else if (event is KeyUpEvent) {
if (plPlayerController.longPressTimer?.tick == 0 && hasPlayer) {
_setVolume(isIncrease: isIncrease);
}
plPlayerController.cancelLongPressTimer();
}
}
bool _handleKey(KeyEvent event) {
final key = event.logicalKey;
final isKeyQ = key == LogicalKeyboardKey.keyQ;
if (isKeyQ || key == LogicalKeyboardKey.keyR) {
if (!plPlayerController.isLive) {
if (event is KeyDownEvent) {
introController!.onStartTriple();
} else if (event is KeyUpEvent) {
introController!.onCancelTriple(isKeyQ);
}
}
return true;
}
final isArrowUp = key == LogicalKeyboardKey.arrowUp;
if (isArrowUp || key == LogicalKeyboardKey.arrowDown) {
_updateVolume(event, isIncrease: isArrowUp);
return true;
}
if (key == LogicalKeyboardKey.arrowRight) {
if (!plPlayerController.isLive) {
if (event is KeyDownEvent) {
if (hasPlayer && !plPlayerController.longPressStatus.value) {
plPlayerController
..cancelLongPressTimer()
..longPressTimer ??= Timer(
const Duration(milliseconds: 200),
() => plPlayerController
..cancelLongPressTimer()
..setLongPressStatus(true),
);
}
} else if (event is KeyUpEvent) {
plPlayerController.cancelLongPressTimer();
if (hasPlayer) {
if (plPlayerController.longPressStatus.value) {
plPlayerController.setLongPressStatus(false);
} else {
plPlayerController.onForward(
plPlayerController.fastForBackwardDuration,
);
}
}
}
}
return true;
}
if (event is KeyDownEvent) {
switch (key) {
case LogicalKeyboardKey.space:
@@ -101,20 +174,6 @@ class PlayerFocus extends StatelessWidget {
plPlayerController.toggleDesktopPip();
return true;
case LogicalKeyboardKey.arrowUp:
if (hasPlayer) {
final volume = math.min(1.0, plPlayerController.volume.value + 0.1);
plPlayerController.setVolume(volume);
}
return true;
case LogicalKeyboardKey.arrowDown:
if (hasPlayer) {
final volume = math.max(0.0, plPlayerController.volume.value - 0.1);
plPlayerController.setVolume(volume);
}
return true;
case LogicalKeyboardKey.keyM:
if (hasPlayer) {
final isMuted = !plPlayerController.isMuted;
@@ -141,10 +200,6 @@ class PlayerFocus extends StatelessWidget {
}
return true;
case LogicalKeyboardKey.keyQ:
introController?.actionLikeVideo();
return true;
case LogicalKeyboardKey.keyW:
introController?.actionCoinVideo();
return true;
@@ -153,7 +208,7 @@ class PlayerFocus extends StatelessWidget {
introController?.actionFavVideo(isQuick: true);
return true;
case LogicalKeyboardKey.keyR:
case LogicalKeyboardKey.keyT || LogicalKeyboardKey.keyV:
introController?.viewLater();
return true;
@@ -182,29 +237,6 @@ class PlayerFocus extends StatelessWidget {
}
}
if (key == LogicalKeyboardKey.arrowRight) {
if (!plPlayerController.isLive && hasPlayer) {
if (event is KeyDownEvent) {
if (!plPlayerController.longPressStatus.value) {
plPlayerController.longPressTimer ??= Timer(
const Duration(milliseconds: 200),
() => plPlayerController.setLongPressStatus(true),
);
}
} else if (event is KeyUpEvent) {
plPlayerController.cancelLongPressTimer();
if (plPlayerController.longPressStatus.value) {
plPlayerController.setLongPressStatus(false);
} else {
plPlayerController.onForward(
plPlayerController.fastForBackwardDuration,
);
}
}
}
return true;
}
return false;
}
}