Skip to content

Commit

Permalink
Merge pull request #523 from xxfttkx/branch-fix-time
Browse files Browse the repository at this point in the history
add forward feature
  • Loading branch information
Predidit authored Dec 27, 2024
2 parents 21595d0 + efecb68 commit 2221f96
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Binary file added assets/images/forward_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions lib/pages/player/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ abstract class _PlayerController with Store {
bool lowMemoryMode = false;
bool autoPlay = true;

int forwardTime = 80;

Future<void> init(String url, {int offset = 0}) async {
videoUrl = url;
playing = false;
Expand Down Expand Up @@ -245,4 +247,8 @@ abstract class _PlayerController with Store {
loading = true;
} catch (_) {}
}

void setForwardTime(int time){
forwardTime = time;
}
}
67 changes: 67 additions & 0 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,7 @@ class _PlayerItemState extends State<PlayerItem>
},
)
: Container(),
forwardIcon(),
Expanded(
child: ProgressBar(
timeLabelLocation: TimeLabelLocation.none,
Expand Down Expand Up @@ -1761,4 +1762,70 @@ class _PlayerItemState extends State<PlayerItem>
hideTimer = null;
});
}


Widget forwardIcon() {
return Tooltip(
message: '长按修改时间',
child: GestureDetector(
onLongPress: () => showForwardChange(),
child: IconButton(
icon: Image.asset(
'assets/images/forward_80.png',
color: Colors.white,
height: 24,
),
onPressed: () {
playerController.seek(playerController.currentPosition +
Duration(seconds: playerController.forwardTime));
},
),
),
);
}

void showForwardChange() {
KazumiDialog.show(builder: (context) {
String input = "";
return AlertDialog(
title: const Text('跳过秒数'),
content: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return TextField(
inputFormatters: [
FilteringTextInputFormatter.digitsOnly, // 只允许输入数字
],
decoration: InputDecoration(
floatingLabelBehavior:
FloatingLabelBehavior.never, // 控制label的显示方式
labelText: playerController.forwardTime.toString(),
),
onChanged: (value) {
input = value;
},
);
}),
actions: <Widget>[
TextButton(
onPressed: () => KazumiDialog.dismiss(),
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
if (input != "") {
playerController.setForwardTime(int.parse(input));
KazumiDialog.dismiss();
} else {
KazumiDialog.dismiss();
}
},
child: const Text('确定'),
),
],
);
});
}
}

0 comments on commit 2221f96

Please sign in to comment.