mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-15 22:09:35 +00:00
123
This commit is contained in:
parent
3810ebc91a
commit
b044d52af0
3 changed files with 50 additions and 26 deletions
|
|
@ -177,6 +177,14 @@ class PlaybackReporter {
|
||||||
deviceInfo: await _getDeviceInfo(),
|
deviceInfo: await _getDeviceInfo(),
|
||||||
forceDirectPlay: false,
|
forceDirectPlay: false,
|
||||||
forceTranscode: false,
|
forceTranscode: false,
|
||||||
|
supportedMimeTypes: [
|
||||||
|
"audio/flac",
|
||||||
|
"audio/mpeg",
|
||||||
|
"audio/mp4",
|
||||||
|
"audio/ogg",
|
||||||
|
"audio/aac",
|
||||||
|
"audio/webm",
|
||||||
|
],
|
||||||
),
|
),
|
||||||
responseErrorHandler: _responseErrorHandler,
|
responseErrorHandler: _responseErrorHandler,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,10 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
final initialPositionInTrack = initialPosition != null
|
final initialPositionInTrack = initialPosition != null
|
||||||
? initialPosition - trackToPlay.startOffset
|
? initialPosition - trackToPlay.startOffset
|
||||||
: null;
|
: null;
|
||||||
await setAudioSourceTrack(initialIndex,
|
await setAudioSourceTrack(
|
||||||
initialPosition: initialPositionInTrack);
|
initialIndex,
|
||||||
|
initialPosition: initialPositionInTrack,
|
||||||
|
);
|
||||||
// _logger.finer('Setting audioSource');
|
// _logger.finer('Setting audioSource');
|
||||||
// await setAudioSource(
|
// await setAudioSource(
|
||||||
// preload: preload,
|
// preload: preload,
|
||||||
|
|
@ -159,27 +161,34 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setAudioSourceTrack(int index,
|
Future<void> setAudioSourceTrack(
|
||||||
{Duration? initialPosition}) async {
|
int index, {
|
||||||
|
Duration? initialPosition,
|
||||||
|
}) async {
|
||||||
if (_book == null) {
|
if (_book == null) {
|
||||||
return stop();
|
return stop();
|
||||||
}
|
}
|
||||||
if (_currentIndex != 0 && index == _currentIndex) {
|
if (_currentIndex != 0 && index == _currentIndex) {
|
||||||
|
if (initialPosition != null && initialPosition <= position) {
|
||||||
|
seek(initialPosition);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentIndex = index;
|
_currentIndex = index;
|
||||||
AudioTrack track = _book!.tracks[index];
|
AudioTrack track = _book!.tracks[index];
|
||||||
final appSettings = loadOrCreateAppSettings();
|
final appSettings = loadOrCreateAppSettings();
|
||||||
final playerSettings =
|
final playerSettings =
|
||||||
readFromBoxOrCreate(_book!.libraryItemId).playerSettings;
|
readFromBoxOrCreate(_book!.libraryItemId).playerSettings;
|
||||||
|
|
||||||
|
if (initialPosition == null || initialPosition <= Duration(seconds: 1)) {
|
||||||
|
initialPosition = playerSettings.skipChapterStart;
|
||||||
|
}
|
||||||
final retrievedUri =
|
final retrievedUri =
|
||||||
_getUri(track, _downloadedUris, baseUrl: baseUrl, token: token);
|
_getUri(track, _downloadedUris, baseUrl: baseUrl, token: token);
|
||||||
|
|
||||||
await setAudioSource(
|
await setAudioSource(
|
||||||
initialPosition: initialPosition == null || initialPosition <= Duration()
|
initialPosition: initialPosition,
|
||||||
? playerSettings.skipChapterStart
|
|
||||||
: initialPosition,
|
|
||||||
ClippingAudioSource(
|
ClippingAudioSource(
|
||||||
end: track.duration - playerSettings.skipChapterEnd,
|
end: track.duration - playerSettings.skipChapterEnd,
|
||||||
child: AudioSource.uri(
|
child: AudioSource.uri(
|
||||||
|
|
@ -263,7 +272,7 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
|
|
||||||
/// seek forward to the next chapter
|
/// seek forward to the next chapter
|
||||||
void seekForward() {
|
void seekForward() {
|
||||||
seekToNext();
|
seekInBook(currentChapter!.end + offset);
|
||||||
// final index = _book!.chapters.indexOf(currentChapter!);
|
// final index = _book!.chapters.indexOf(currentChapter!);
|
||||||
// if (index < _book!.chapters.length - 1) {
|
// if (index < _book!.chapters.length - 1) {
|
||||||
// super.seek(
|
// super.seek(
|
||||||
|
|
@ -274,6 +283,30 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// seek backward to the previous chapter or the start of the current chapter
|
||||||
|
void seekBackward() {
|
||||||
|
final currentPlayingChapterIndex = _book!.chapters.indexOf(currentChapter!);
|
||||||
|
if (position > doNotSeekBackIfLessThan || currentPlayingChapterIndex <= 0) {
|
||||||
|
seekInBook(currentChapter!.start + offset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BookChapter chapterToSeekTo =
|
||||||
|
_book!.chapters[currentPlayingChapterIndex - 1];
|
||||||
|
seekInBook(chapterToSeekTo.start + offset);
|
||||||
|
// final currentPlayingChapterIndex = _book!.chapters.indexOf(currentChapter!);
|
||||||
|
// final chapterPosition = positionInBook - currentChapter!.start;
|
||||||
|
// BookChapter chapterToSeekTo;
|
||||||
|
// // if player position is less than 5 seconds into the chapter, go to the previous chapter
|
||||||
|
// if (chapterPosition < doNotSeekBackIfLessThan && currentPlayingChapterIndex > 0) {
|
||||||
|
// chapterToSeekTo = _book!.chapters[currentPlayingChapterIndex - 1];
|
||||||
|
// } else {
|
||||||
|
// chapterToSeekTo = currentChapter!;
|
||||||
|
// }
|
||||||
|
// super.seek(
|
||||||
|
// chapterToSeekTo.start + offset,
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> seekToNext() {
|
Future<void> seekToNext() {
|
||||||
if (_currentIndex >= availableTracks!) {
|
if (_currentIndex >= availableTracks!) {
|
||||||
|
|
@ -290,23 +323,6 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
return setAudioSourceTrack(_currentIndex - 1);
|
return setAudioSourceTrack(_currentIndex - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// seek backward to the previous chapter or the start of the current chapter
|
|
||||||
void seekBackward() {
|
|
||||||
seekToPrevious();
|
|
||||||
// final currentPlayingChapterIndex = _book!.chapters.indexOf(currentChapter!);
|
|
||||||
// final chapterPosition = positionInBook - currentChapter!.start;
|
|
||||||
// BookChapter chapterToSeekTo;
|
|
||||||
// // if player position is less than 5 seconds into the chapter, go to the previous chapter
|
|
||||||
// if (chapterPosition < doNotSeekBackIfLessThan && currentPlayingChapterIndex > 0) {
|
|
||||||
// chapterToSeekTo = _book!.chapters[currentPlayingChapterIndex - 1];
|
|
||||||
// } else {
|
|
||||||
// chapterToSeekTo = currentChapter!;
|
|
||||||
// }
|
|
||||||
// super.seek(
|
|
||||||
// chapterToSeekTo.start + offset,
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
/// a convenience method to get position in the book instead of the current track position
|
/// a convenience method to get position in the book instead of the current track position
|
||||||
Duration get positionInBook {
|
Duration get positionInBook {
|
||||||
if (_book == null) {
|
if (_book == null) {
|
||||||
|
|
|
||||||
2
shelfsdk
2
shelfsdk
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4f19af242158bfb58f0b6893af9a11201a7b638a
|
Subproject commit e1848a42c27257146015a33e9427f197f522fe03
|
||||||
Loading…
Add table
Add a link
Reference in a new issue