Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions lib/pages/player/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ abstract class _PlayerController with Store {
try {
await mediaPlayer.dispose();
} catch (_) {}

// // 清理定时关闭的定时器和ValueNotifier
// closeTimer?.cancel();
// closeTimer = null;
// showCountDown.dispose();
}

Future<void> stop() async {
Expand Down Expand Up @@ -496,7 +501,8 @@ abstract class _PlayerController with Store {
}

Future<void> createSyncPlayRoom(
String room, String username, Function changeEpisode, {bool enableTLS = false}) async {
String room, String username, Function changeEpisode,
{bool enableTLS = false}) async {
await syncplayController?.disconnect();
syncplayController = SyncplayClient(host: 'syncplay.pl', port: 8995);
try {
Expand Down Expand Up @@ -530,7 +536,8 @@ abstract class _PlayerController with Store {
setSyncPlayPlayingBangumi();
} else {
KazumiDialog.showToast(
message: 'SyncPlay: 您不是当前房间中的唯一用户, 当前以用户 ${message['username']} 进度为准');
message:
'SyncPlay: 您不是当前房间中的唯一用户, 当前以用户 ${message['username']} 进度为准');
}
}
if (message['type'] == 'left') {
Expand Down Expand Up @@ -571,7 +578,8 @@ abstract class _PlayerController with Store {
(message) {
if (message['username'] != username) {
KazumiDialog.showToast(
message: 'SyncPlay: ${message['username']} 说: ${message['message']}',
message:
'SyncPlay: ${message['username']} 说: ${message['message']}',
duration: const Duration(seconds: 5));
}
},
Expand Down Expand Up @@ -668,4 +676,41 @@ abstract class _PlayerController with Store {
syncplayRoom = '';
syncplayClientRtt = 0;
}

// 定时关闭
bool isCloseTimerEnabled = false;
Timer? closeTimer;
int timeToClose = 0;
int remainingTime = 0;
final ValueNotifier<String> showCountDown = ValueNotifier<String>("");
VoidCallback? onShowTimeReset;

String formatTime(int seconds) {
Duration duration = Duration(seconds: seconds);
String twoDigits(int n) => n.toString().padLeft(2, '0');
String hours = twoDigits(duration.inHours);
String minutes = twoDigits(duration.inMinutes.remainder(60));
String secs = twoDigits(duration.inSeconds.remainder(60));
return "$hours:$minutes:$secs";
}

void startCloseTimer() {
closeTimer?.cancel();
remainingTime = timeToClose;
isCloseTimerEnabled = true;
showCountDown.value = formatTime(remainingTime - 1);
closeTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (remainingTime > 1) {
remainingTime--;
showCountDown.value = formatTime(remainingTime - 1);
} else {
pause();
timer.cancel();
isCloseTimerEnabled = false;
if (onShowTimeReset != null) {
onShowTimeReset!();
}
}
});
}
}
Loading