mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: set playback speed
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -161,9 +161,9 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
hideTop: playerController.blockTypes.contains(5),
|
||||
hideScroll: playerController.blockTypes.contains(2),
|
||||
hideBottom: playerController.blockTypes.contains(4),
|
||||
duration: playerController.danmakuDuration ~/
|
||||
duration: playerController.danmakuDuration /
|
||||
playerController.playbackSpeed,
|
||||
staticDuration: playerController.danmakuStaticDuration ~/
|
||||
staticDuration: playerController.danmakuStaticDuration /
|
||||
playerController.playbackSpeed,
|
||||
strokeWidth: playerController.strokeWidth,
|
||||
lineHeight: playerController.danmakuLineHeight,
|
||||
|
||||
@@ -180,10 +180,10 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
hideTop: plPlayerController.blockTypes.contains(5),
|
||||
hideScroll: plPlayerController.blockTypes.contains(2),
|
||||
hideBottom: plPlayerController.blockTypes.contains(4),
|
||||
duration: plPlayerController.danmakuDuration ~/
|
||||
duration: plPlayerController.danmakuDuration /
|
||||
plPlayerController.playbackSpeed,
|
||||
staticDuration:
|
||||
plPlayerController.danmakuStaticDuration ~/
|
||||
plPlayerController.danmakuStaticDuration /
|
||||
plPlayerController.playbackSpeed,
|
||||
strokeWidth: plPlayerController.strokeWidth,
|
||||
lineHeight: plPlayerController.danmakuLineHeight,
|
||||
|
||||
@@ -272,8 +272,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
// 结束播放退出全屏
|
||||
if (!notExitFlag && autoExitFullscreen) {
|
||||
plPlayerController!.triggerFullScreen(status: false);
|
||||
if (plPlayerController!.doubleSpeedStatus.value) {
|
||||
plPlayerController!.setDoubleSpeedStatus(false);
|
||||
if (plPlayerController!.longPressStatus.value) {
|
||||
plPlayerController!.setLongPressStatus(false);
|
||||
}
|
||||
if (plPlayerController!.controlsLock.value) {
|
||||
plPlayerController!.onLockControl(false);
|
||||
|
||||
@@ -302,8 +302,8 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
// 结束播放退出全屏
|
||||
if (!notExitFlag && autoExitFullscreen) {
|
||||
plPlayerController!.triggerFullScreen(status: false);
|
||||
if (plPlayerController!.doubleSpeedStatus.value) {
|
||||
plPlayerController!.setDoubleSpeedStatus(false);
|
||||
if (plPlayerController!.longPressStatus.value) {
|
||||
plPlayerController!.setLongPressStatus(false);
|
||||
}
|
||||
if (plPlayerController!.controlsLock.value) {
|
||||
plPlayerController!.onLockControl(false);
|
||||
|
||||
@@ -1520,7 +1520,7 @@ class _HeaderControlState extends State<HeaderControl> {
|
||||
danmakuController?.updateOption(
|
||||
danmakuController.option.copyWith(
|
||||
duration:
|
||||
danmakuDuration ~/ widget.controller.playbackSpeed),
|
||||
danmakuDuration / widget.controller.playbackSpeed),
|
||||
);
|
||||
} catch (_) {}
|
||||
}
|
||||
@@ -1534,7 +1534,7 @@ class _HeaderControlState extends State<HeaderControl> {
|
||||
try {
|
||||
danmakuController?.updateOption(
|
||||
danmakuController.option.copyWith(
|
||||
staticDuration: danmakuStaticDuration ~/
|
||||
staticDuration: danmakuStaticDuration /
|
||||
widget.controller.playbackSpeed),
|
||||
);
|
||||
} catch (_) {}
|
||||
|
||||
@@ -65,6 +65,7 @@ class PlPlayerController {
|
||||
|
||||
final Rx<int> _playerCount = Rx(0);
|
||||
|
||||
late double lastPlaybackSpeed = 1.0;
|
||||
final Rx<double> _playbackSpeed = 1.0.obs;
|
||||
final Rx<double> _longPressSpeed = 2.0.obs;
|
||||
final Rx<double> _currentVolume = 1.0.obs;
|
||||
@@ -74,7 +75,7 @@ class PlPlayerController {
|
||||
final Rx<bool> _showControls = false.obs;
|
||||
final Rx<bool> _showVolumeStatus = false.obs;
|
||||
final Rx<bool> _showBrightnessStatus = false.obs;
|
||||
final Rx<bool> _doubleSpeedStatus = false.obs;
|
||||
final Rx<bool> _longPressStatus = false.obs;
|
||||
final Rx<bool> _controlsLock = false.obs;
|
||||
final Rx<bool> _isFullScreen = false.obs;
|
||||
// 默认投稿视频格式
|
||||
@@ -232,7 +233,7 @@ class PlPlayerController {
|
||||
Rx<bool> get flipY => _flipY;
|
||||
|
||||
/// 是否长按倍速
|
||||
Rx<bool> get doubleSpeedStatus => _doubleSpeedStatus;
|
||||
Rx<bool> get longPressStatus => _longPressStatus;
|
||||
|
||||
Rx<bool> isBuffering = true.obs;
|
||||
|
||||
@@ -277,7 +278,6 @@ class PlPlayerController {
|
||||
late double danmakuDuration;
|
||||
late double danmakuStaticDuration;
|
||||
late List<double> speedList;
|
||||
double? defaultDuration;
|
||||
late bool enableAutoLongPressSpeed = false;
|
||||
late bool enableLongShowControl;
|
||||
double subtitleFontScale = 1.0;
|
||||
@@ -806,11 +806,7 @@ class PlPlayerController {
|
||||
if (videoType.value == 'live') {
|
||||
await setPlaybackSpeed(1.0);
|
||||
} else {
|
||||
if (_playbackSpeed.value != 1.0) {
|
||||
await setPlaybackSpeed(_playbackSpeed.value);
|
||||
} else {
|
||||
await setPlaybackSpeed(1.0);
|
||||
}
|
||||
await setPlaybackSpeed(_playbackSpeed.value);
|
||||
}
|
||||
getVideoFit();
|
||||
// if (_looping) {
|
||||
@@ -1036,23 +1032,25 @@ class PlPlayerController {
|
||||
|
||||
/// 设置倍速
|
||||
Future<void> setPlaybackSpeed(double speed) async {
|
||||
/// TODO _duration.value丢失
|
||||
await _videoPlayerController?.setRate(speed);
|
||||
try {
|
||||
DanmakuOption currentOption = danmakuController!.option;
|
||||
defaultDuration ??=
|
||||
currentOption.duration.toDouble() * _playbackSpeed.value;
|
||||
DanmakuOption updatedOption =
|
||||
currentOption.copyWith(duration: defaultDuration! ~/ speed);
|
||||
danmakuController!.updateOption(updatedOption);
|
||||
if (speed == 1.0) {
|
||||
defaultDuration = null;
|
||||
}
|
||||
} catch (_) {}
|
||||
// fix 长按倍速后放开不恢复
|
||||
if (!doubleSpeedStatus.value) {
|
||||
_playbackSpeed.value = speed;
|
||||
lastPlaybackSpeed = playbackSpeed;
|
||||
|
||||
if (speed == playbackSpeed) {
|
||||
return;
|
||||
}
|
||||
|
||||
await _videoPlayerController?.setRate(speed);
|
||||
if (danmakuController != null) {
|
||||
DanmakuOption currentOption = danmakuController!.option;
|
||||
double defaultDuration = currentOption.duration * lastPlaybackSpeed;
|
||||
double defaultStaticDuration =
|
||||
currentOption.staticDuration * lastPlaybackSpeed;
|
||||
DanmakuOption updatedOption = currentOption.copyWith(
|
||||
duration: defaultDuration / speed,
|
||||
staticDuration: defaultStaticDuration / speed,
|
||||
);
|
||||
danmakuController!.updateOption(updatedOption);
|
||||
}
|
||||
_playbackSpeed.value = speed;
|
||||
}
|
||||
|
||||
// 还原默认速度
|
||||
@@ -1339,27 +1337,27 @@ class PlPlayerController {
|
||||
}
|
||||
|
||||
/// 设置长按倍速状态 live模式下禁用
|
||||
void setDoubleSpeedStatus(bool val) async {
|
||||
void setLongPressStatus(bool val) async {
|
||||
if (videoType.value == 'live') {
|
||||
return;
|
||||
}
|
||||
if (controlsLock.value) {
|
||||
return;
|
||||
}
|
||||
if (_doubleSpeedStatus.value == val) {
|
||||
if (_longPressStatus.value == val) {
|
||||
return;
|
||||
}
|
||||
if (val) {
|
||||
if (playerStatus.status.value == PlayerStatus.playing) {
|
||||
_doubleSpeedStatus.value = val;
|
||||
_longPressStatus.value = val;
|
||||
HapticFeedback.lightImpact();
|
||||
await setPlaybackSpeed(
|
||||
enableAutoLongPressSpeed ? playbackSpeed * 2 : longPressSpeed);
|
||||
}
|
||||
} else {
|
||||
// debugPrint('$playbackSpeed');
|
||||
_doubleSpeedStatus.value = val;
|
||||
await setPlaybackSpeed(playbackSpeed);
|
||||
_longPressStatus.value = val;
|
||||
await setPlaybackSpeed(lastPlaybackSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -946,7 +946,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
translation: const Offset(0.0, 0.3), // 上下偏移量(负数向上偏移)
|
||||
child: AnimatedOpacity(
|
||||
curve: Curves.easeInOut,
|
||||
opacity: plPlayerController.doubleSpeedStatus.value ? 1.0 : 0.0,
|
||||
opacity: plPlayerController.longPressStatus.value ? 1.0 : 0.0,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
@@ -959,7 +959,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
child: Center(
|
||||
child: Obx(
|
||||
() => Text(
|
||||
'${plPlayerController.enableAutoLongPressSpeed ? plPlayerController.playbackSpeed * 2 : plPlayerController.longPressSpeed}倍速中',
|
||||
'${plPlayerController.enableAutoLongPressSpeed ? (plPlayerController.longPressStatus.value ? plPlayerController.lastPlaybackSpeed : plPlayerController.playbackSpeed) * 2 : plPlayerController.longPressSpeed}倍速中',
|
||||
style:
|
||||
const TextStyle(color: Colors.white, fontSize: 13),
|
||||
),
|
||||
@@ -1255,10 +1255,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
doubleTapFuc(type);
|
||||
},
|
||||
onLongPressStart: (LongPressStartDetails detail) {
|
||||
plPlayerController.setDoubleSpeedStatus(true);
|
||||
plPlayerController.setLongPressStatus(true);
|
||||
},
|
||||
onLongPressEnd: (LongPressEndDetails details) {
|
||||
plPlayerController.setDoubleSpeedStatus(false);
|
||||
plPlayerController.setLongPressStatus(false);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -252,7 +252,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: "5391050a7e070a85234762edadc93298c6ed6523"
|
||||
resolved-ref: "23269eb39f4374b7cbf7154e47918213e174373d"
|
||||
url: "https://github.com/bggRGjQaUbCoE/canvas_danmaku.git"
|
||||
source: git
|
||||
version: "0.2.6"
|
||||
|
||||
Reference in New Issue
Block a user