fix: forward and backward issues

This commit is contained in:
22
2025-10-05 09:28:42 +08:00
parent a6414701e8
commit 4c170f6dd5
7 changed files with 29 additions and 34 deletions

View File

@@ -3,12 +3,14 @@
### Changelog
* Adjusted the playback control bar style in compact layout
* Clicking “Check update” in the Microsoft Store version redirects to the Store page.
* Clicking “Check update” in the Microsoft Store version redirects to the Store page
* Fixed forward and backward issues
### 更新日志
* 调整了紧凑布局下的播放控制栏样式
* 微软商店版本中点击检查更新将跳转至商店页面
* 修复了快退快进的问题
## v1.5.0

View File

@@ -6,7 +6,6 @@ import 'package:provider/provider.dart';
void useAppLifecycle() {
final context = useContext();
final saveProgress = context.read<MediaPlayer>().saveProgress;
AppLifecycleState? appLifecycleState = useAppLifecycleState();
@@ -14,7 +13,7 @@ void useAppLifecycle() {
try {
if (appLifecycleState == AppLifecycleState.paused) {
logger('App lifecycle state: paused');
saveProgress();
context.read<MediaPlayer>().saveProgress();
}
} catch (e) {
logger('App lifecycle state error: $e');

View File

@@ -32,7 +32,6 @@ class Gesture {
final bool isRightGesture;
final double? brightness;
final double? volume;
final MouseCursor cursor;
Gesture({
required this.onTapDown,
@@ -52,7 +51,6 @@ class Gesture {
required this.isRightGesture,
required this.brightness,
required this.volume,
required this.cursor,
});
}
@@ -66,8 +64,6 @@ Gesture useGesture({
}) {
final context = useContext();
final player = context.read<MediaPlayer>();
final gestureState = useRef({
'isTouch': false,
'isLongPress': false,
@@ -98,6 +94,8 @@ Gesture useGesture({
}
void onDoubleTapDown(TapDownDetails details) {
final player = context.read<MediaPlayer>();
if (details.kind == PointerDeviceKind.touch) {
final screenWidth = MediaQuery.sizeOf(context).width;
final tapDx = details.globalPosition.dx;
@@ -129,7 +127,8 @@ Gesture useGesture({
}
void onLongPressStart(LongPressStartDetails details) {
if (gestureState.value['isTouch'] as bool && player.isPlaying) {
if (gestureState.value['isTouch'] as bool &&
context.read<MediaPlayer>().isPlaying) {
gestureState.value['isLongPress'] = true;
gestureState.value['startPanOffset'] = details.globalPosition;
@@ -207,7 +206,8 @@ Gesture useGesture({
gestureState.value['isTouch'] = true;
gestureState.value['isDragging'] = true;
gestureState.value['startPanOffset'] = details.globalPosition;
gestureState.value['startSeekPosition'] = player.position;
gestureState.value['startSeekPosition'] =
context.read<MediaPlayer>().position;
gestureState.value['panDirection'] = null;
isLeftGesture.value = false;
isRightGesture.value = false;
@@ -247,9 +247,10 @@ Gesture useGesture({
int targetSeconds = (startSeconds + seekSecondsOffset).round();
// 边界检查
targetSeconds = targetSeconds.clamp(0, player.duration.inSeconds);
targetSeconds = targetSeconds.clamp(
0, context.read<MediaPlayer>().duration.inSeconds);
player.seek(Duration(seconds: targetSeconds));
context.read<MediaPlayer>().seek(Duration(seconds: targetSeconds));
showProgress();
}
@@ -306,12 +307,6 @@ Gesture useGesture({
}
}
final cursor = useMemoized(() {
return player.isPlaying == false
? SystemMouseCursors.basic
: SystemMouseCursors.none;
}, [player.isPlaying]);
return Gesture(
onTapDown: onTapDown,
onTap: onTap,
@@ -330,6 +325,5 @@ Gesture useGesture({
isRightGesture: isRightGesture.value,
brightness: brightness.value,
volume: volume.value,
cursor: cursor,
);
}

View File

@@ -28,9 +28,9 @@ KeyboardEvent useKeyboard({
}) {
final context = useContext();
final player = context.read<MediaPlayer>();
void onKeyEvent(KeyEvent event) async {
final player = context.read<MediaPlayer>();
if (event.runtimeType == KeyDownEvent) {
if (HardwareKeyboard.instance.isAltPressed) {
switch (event.logicalKey) {
@@ -138,7 +138,7 @@ KeyboardEvent useKeyboard({
case LogicalKeyboardKey.space:
case LogicalKeyboardKey.mediaPlayPause:
showControl();
if (context.read<MediaPlayer>().isPlaying) {
if (player.isPlaying) {
useAppStore().updateAutoPlay(false);
player.pause();
} else {

View File

@@ -52,8 +52,6 @@ class ControlBar extends HookWidget {
final isInitializing =
context.select<MediaPlayer, bool>((player) => player.isInitializing);
final player = context.read<MediaPlayer>();
final rate = useAppStore().select(context, (state) => state.rate);
final volume = useAppStore().select(context, (state) => state.volume);
final isMuted = useAppStore().select(context, (state) => state.isMuted);
@@ -117,10 +115,10 @@ class ControlBar extends HookWidget {
showControl();
if (isPlaying == true) {
useAppStore().updateAutoPlay(false);
player.pause();
context.read<MediaPlayer>().pause();
} else {
useAppStore().updateAutoPlay(true);
player.play();
context.read<MediaPlayer>().play();
}
},
style: ButtonStyle(overlayColor: overlayColor),
@@ -138,7 +136,7 @@ class ControlBar extends HookWidget {
onPressed: () {
showControl();
useAppStore().updateAutoPlay(false);
player.pause();
context.read<MediaPlayer>().pause();
usePlayQueueStore().updateCurrentIndex(-1);
},
style: ButtonStyle(overlayColor: overlayColor),
@@ -521,7 +519,7 @@ class ControlBar extends HookWidget {
),
),
onTap: () async {
await player.saveProgress();
await context.read<MediaPlayer>().saveProgress();
if (isDesktop) {
windowManager.close();
} else {

View File

@@ -29,6 +29,12 @@ class GestureOverlay extends HookWidget {
final isShowControl =
usePlayerUiStore().select(context, (state) => state.isShowControl);
final cursor = useMemoized(
() => isShowControl || !isPlaying
? SystemMouseCursors.basic
: SystemMouseCursors.none,
[isShowControl, isPlaying]);
final isSpeedSelectorVisible = useState(false);
final selectedSpeed = useState(1.0);
final speedSelectorPosition = useState(Offset.zero);
@@ -75,9 +81,7 @@ class GestureOverlay extends HookWidget {
);
return MouseRegion(
cursor: isShowControl || isPlaying == false
? SystemMouseCursors.basic
: SystemMouseCursors.none,
cursor: cursor,
onHover: gesture.onHover,
child: GestureDetector(
behavior: HitTestBehavior.opaque,

View File

@@ -35,8 +35,6 @@ class Player extends HookWidget {
final height =
context.select<MediaPlayer, double>((player) => player.height);
final saveProgress = context.read<MediaPlayer>().saveProgress;
useAppLifecycle();
final cover = useCover();
@@ -123,7 +121,7 @@ class Player extends HookWidget {
Future<void> showControlForHover(Future<void> callback) async {
try {
saveProgress();
context.read<MediaPlayer>().saveProgress();
showControl();
usePlayerUiStore().updateIsHovering(true);
await callback;
@@ -216,7 +214,7 @@ class Player extends HookWidget {
canPop: false,
onPopInvokedWithResult: (bool didPop, Object? result) async {
if (!didPop) {
await saveProgress();
await context.read<MediaPlayer>().saveProgress();
if (isDesktop) {
windowManager.close();
} else {