chapter selection in player

This commit is contained in:
Dr-Blank 2024-08-20 10:14:07 -04:00
parent c24541f1cd
commit ec8304fdc3
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
7 changed files with 163 additions and 14 deletions

View file

@ -0,0 +1,8 @@
import 'package:shelfsdk/audiobookshelf_api.dart';
extension ChapterDuration on BookChapter {
Duration get duration {
// end - start
return end - start;
}
}

View file

@ -1,12 +1,20 @@
extension DurationFormat on Duration {
/// formats the duration of the book as `10h 30m`
/// formats the duration using only 2 units
///
/// will add up all the durations of the audio files first
/// then convert them to the given format
String get formattedBinary {
/// if the duration is more than 1 hour, it will return `10h 30m`
/// if the duration is less than 1 hour, it will return `30m 20s`
/// if the duration is less than 1 minute, it will return `20s`
String get smartBinaryFormat {
final hours = inHours;
final minutes = inMinutes.remainder(60);
return '${hours}h ${minutes}m';
final seconds = inSeconds.remainder(60);
if (hours > 0) {
return '${hours}h ${minutes}m';
} else if (minutes > 0) {
return '${minutes}m ${seconds}s';
} else {
return '${seconds}s';
}
}
}

View file

@ -15,3 +15,16 @@ void useInterval(VoidCallback callback, Duration delay) {
[delay],
);
}
void useTimer(VoidCallback callback, Duration delay) {
final savedCallback = useRef(callback);
savedCallback.value = callback;
useEffect(
() {
final timer = Timer(delay, savedCallback.value);
return timer.cancel;
},
[delay],
);
}

View file

@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
void showNotImplementedToast(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Not implemented"),
showCloseIcon: true,
),
);
}