Skip to content

Commit 4c170f6

Browse files
committed
fix: forward and backward issues
1 parent a641470 commit 4c170f6

7 files changed

Lines changed: 29 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
### Changelog
44

55
* Adjusted the playback control bar style in compact layout
6-
* Clicking “Check update” in the Microsoft Store version redirects to the Store page.
6+
* Clicking “Check update” in the Microsoft Store version redirects to the Store page
7+
* Fixed forward and backward issues
78

89
### 更新日志
910

1011
* 调整了紧凑布局下的播放控制栏样式
1112
* 微软商店版本中点击检查更新将跳转至商店页面
13+
* 修复了快退快进的问题
1214

1315
## v1.5.0
1416

lib/hooks/use_app_lifecycle.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import 'package:provider/provider.dart';
66

77
void useAppLifecycle() {
88
final context = useContext();
9-
final saveProgress = context.read<MediaPlayer>().saveProgress;
109

1110
AppLifecycleState? appLifecycleState = useAppLifecycleState();
1211

1312
useEffect(() {
1413
try {
1514
if (appLifecycleState == AppLifecycleState.paused) {
1615
logger('App lifecycle state: paused');
17-
saveProgress();
16+
context.read<MediaPlayer>().saveProgress();
1817
}
1918
} catch (e) {
2019
logger('App lifecycle state error: $e');

lib/hooks/use_gesture.dart

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class Gesture {
3232
final bool isRightGesture;
3333
final double? brightness;
3434
final double? volume;
35-
final MouseCursor cursor;
3635

3736
Gesture({
3837
required this.onTapDown,
@@ -52,7 +51,6 @@ class Gesture {
5251
required this.isRightGesture,
5352
required this.brightness,
5453
required this.volume,
55-
required this.cursor,
5654
});
5755
}
5856

@@ -66,8 +64,6 @@ Gesture useGesture({
6664
}) {
6765
final context = useContext();
6866

69-
final player = context.read<MediaPlayer>();
70-
7167
final gestureState = useRef({
7268
'isTouch': false,
7369
'isLongPress': false,
@@ -98,6 +94,8 @@ Gesture useGesture({
9894
}
9995

10096
void onDoubleTapDown(TapDownDetails details) {
97+
final player = context.read<MediaPlayer>();
98+
10199
if (details.kind == PointerDeviceKind.touch) {
102100
final screenWidth = MediaQuery.sizeOf(context).width;
103101
final tapDx = details.globalPosition.dx;
@@ -129,7 +127,8 @@ Gesture useGesture({
129127
}
130128

131129
void onLongPressStart(LongPressStartDetails details) {
132-
if (gestureState.value['isTouch'] as bool && player.isPlaying) {
130+
if (gestureState.value['isTouch'] as bool &&
131+
context.read<MediaPlayer>().isPlaying) {
133132
gestureState.value['isLongPress'] = true;
134133
gestureState.value['startPanOffset'] = details.globalPosition;
135134

@@ -207,7 +206,8 @@ Gesture useGesture({
207206
gestureState.value['isTouch'] = true;
208207
gestureState.value['isDragging'] = true;
209208
gestureState.value['startPanOffset'] = details.globalPosition;
210-
gestureState.value['startSeekPosition'] = player.position;
209+
gestureState.value['startSeekPosition'] =
210+
context.read<MediaPlayer>().position;
211211
gestureState.value['panDirection'] = null;
212212
isLeftGesture.value = false;
213213
isRightGesture.value = false;
@@ -247,9 +247,10 @@ Gesture useGesture({
247247
int targetSeconds = (startSeconds + seekSecondsOffset).round();
248248

249249
// 边界检查
250-
targetSeconds = targetSeconds.clamp(0, player.duration.inSeconds);
250+
targetSeconds = targetSeconds.clamp(
251+
0, context.read<MediaPlayer>().duration.inSeconds);
251252

252-
player.seek(Duration(seconds: targetSeconds));
253+
context.read<MediaPlayer>().seek(Duration(seconds: targetSeconds));
253254
showProgress();
254255
}
255256

@@ -306,12 +307,6 @@ Gesture useGesture({
306307
}
307308
}
308309

309-
final cursor = useMemoized(() {
310-
return player.isPlaying == false
311-
? SystemMouseCursors.basic
312-
: SystemMouseCursors.none;
313-
}, [player.isPlaying]);
314-
315310
return Gesture(
316311
onTapDown: onTapDown,
317312
onTap: onTap,
@@ -330,6 +325,5 @@ Gesture useGesture({
330325
isRightGesture: isRightGesture.value,
331326
brightness: brightness.value,
332327
volume: volume.value,
333-
cursor: cursor,
334328
);
335329
}

lib/hooks/use_keyboard.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ KeyboardEvent useKeyboard({
2828
}) {
2929
final context = useContext();
3030

31-
final player = context.read<MediaPlayer>();
32-
3331
void onKeyEvent(KeyEvent event) async {
32+
final player = context.read<MediaPlayer>();
33+
3434
if (event.runtimeType == KeyDownEvent) {
3535
if (HardwareKeyboard.instance.isAltPressed) {
3636
switch (event.logicalKey) {
@@ -138,7 +138,7 @@ KeyboardEvent useKeyboard({
138138
case LogicalKeyboardKey.space:
139139
case LogicalKeyboardKey.mediaPlayPause:
140140
showControl();
141-
if (context.read<MediaPlayer>().isPlaying) {
141+
if (player.isPlaying) {
142142
useAppStore().updateAutoPlay(false);
143143
player.pause();
144144
} else {

lib/pages/player/control_bar/control_bar.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class ControlBar extends HookWidget {
5252
final isInitializing =
5353
context.select<MediaPlayer, bool>((player) => player.isInitializing);
5454

55-
final player = context.read<MediaPlayer>();
56-
5755
final rate = useAppStore().select(context, (state) => state.rate);
5856
final volume = useAppStore().select(context, (state) => state.volume);
5957
final isMuted = useAppStore().select(context, (state) => state.isMuted);
@@ -117,10 +115,10 @@ class ControlBar extends HookWidget {
117115
showControl();
118116
if (isPlaying == true) {
119117
useAppStore().updateAutoPlay(false);
120-
player.pause();
118+
context.read<MediaPlayer>().pause();
121119
} else {
122120
useAppStore().updateAutoPlay(true);
123-
player.play();
121+
context.read<MediaPlayer>().play();
124122
}
125123
},
126124
style: ButtonStyle(overlayColor: overlayColor),
@@ -138,7 +136,7 @@ class ControlBar extends HookWidget {
138136
onPressed: () {
139137
showControl();
140138
useAppStore().updateAutoPlay(false);
141-
player.pause();
139+
context.read<MediaPlayer>().pause();
142140
usePlayQueueStore().updateCurrentIndex(-1);
143141
},
144142
style: ButtonStyle(overlayColor: overlayColor),
@@ -521,7 +519,7 @@ class ControlBar extends HookWidget {
521519
),
522520
),
523521
onTap: () async {
524-
await player.saveProgress();
522+
await context.read<MediaPlayer>().saveProgress();
525523
if (isDesktop) {
526524
windowManager.close();
527525
} else {

lib/pages/player/overlays/gesture_overlay.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class GestureOverlay extends HookWidget {
2929
final isShowControl =
3030
usePlayerUiStore().select(context, (state) => state.isShowControl);
3131

32+
final cursor = useMemoized(
33+
() => isShowControl || !isPlaying
34+
? SystemMouseCursors.basic
35+
: SystemMouseCursors.none,
36+
[isShowControl, isPlaying]);
37+
3238
final isSpeedSelectorVisible = useState(false);
3339
final selectedSpeed = useState(1.0);
3440
final speedSelectorPosition = useState(Offset.zero);
@@ -75,9 +81,7 @@ class GestureOverlay extends HookWidget {
7581
);
7682

7783
return MouseRegion(
78-
cursor: isShowControl || isPlaying == false
79-
? SystemMouseCursors.basic
80-
: SystemMouseCursors.none,
84+
cursor: cursor,
8185
onHover: gesture.onHover,
8286
child: GestureDetector(
8387
behavior: HitTestBehavior.opaque,

lib/pages/player/player.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class Player extends HookWidget {
3535
final height =
3636
context.select<MediaPlayer, double>((player) => player.height);
3737

38-
final saveProgress = context.read<MediaPlayer>().saveProgress;
39-
4038
useAppLifecycle();
4139

4240
final cover = useCover();
@@ -123,7 +121,7 @@ class Player extends HookWidget {
123121

124122
Future<void> showControlForHover(Future<void> callback) async {
125123
try {
126-
saveProgress();
124+
context.read<MediaPlayer>().saveProgress();
127125
showControl();
128126
usePlayerUiStore().updateIsHovering(true);
129127
await callback;
@@ -216,7 +214,7 @@ class Player extends HookWidget {
216214
canPop: false,
217215
onPopInvokedWithResult: (bool didPop, Object? result) async {
218216
if (!didPop) {
219-
await saveProgress();
217+
await context.read<MediaPlayer>().saveProgress();
220218
if (isDesktop) {
221219
windowManager.close();
222220
} else {

0 commit comments

Comments
 (0)