diff --git a/lib/features/playback_reporting/core/playback_reporter.dart b/lib/features/playback_reporting/core/playback_reporter.dart index b2be336..5fba5af 100644 --- a/lib/features/playback_reporting/core/playback_reporter.dart +++ b/lib/features/playback_reporting/core/playback_reporter.dart @@ -177,6 +177,14 @@ class PlaybackReporter { deviceInfo: await _getDeviceInfo(), forceDirectPlay: false, forceTranscode: false, + supportedMimeTypes: [ + "audio/flac", + "audio/mpeg", + "audio/mp4", + "audio/ogg", + "audio/aac", + "audio/webm", + ], ), responseErrorHandler: _responseErrorHandler, ); diff --git a/lib/features/player/core/audiobook_player.dart b/lib/features/player/core/audiobook_player.dart index dae5fc0..c64e244 100644 --- a/lib/features/player/core/audiobook_player.dart +++ b/lib/features/player/core/audiobook_player.dart @@ -124,8 +124,10 @@ class AudiobookPlayer extends AudioPlayer { final initialPositionInTrack = initialPosition != null ? initialPosition - trackToPlay.startOffset : null; - await setAudioSourceTrack(initialIndex, - initialPosition: initialPositionInTrack); + await setAudioSourceTrack( + initialIndex, + initialPosition: initialPositionInTrack, + ); // _logger.finer('Setting audioSource'); // await setAudioSource( // preload: preload, @@ -159,27 +161,34 @@ class AudiobookPlayer extends AudioPlayer { // }); } - Future setAudioSourceTrack(int index, - {Duration? initialPosition}) async { + Future setAudioSourceTrack( + int index, { + Duration? initialPosition, + }) async { if (_book == null) { return stop(); } if (_currentIndex != 0 && index == _currentIndex) { + if (initialPosition != null && initialPosition <= position) { + seek(initialPosition); + } return; } + _currentIndex = index; AudioTrack track = _book!.tracks[index]; final appSettings = loadOrCreateAppSettings(); final playerSettings = readFromBoxOrCreate(_book!.libraryItemId).playerSettings; + if (initialPosition == null || initialPosition <= Duration(seconds: 1)) { + initialPosition = playerSettings.skipChapterStart; + } final retrievedUri = _getUri(track, _downloadedUris, baseUrl: baseUrl, token: token); await setAudioSource( - initialPosition: initialPosition == null || initialPosition <= Duration() - ? playerSettings.skipChapterStart - : initialPosition, + initialPosition: initialPosition, ClippingAudioSource( end: track.duration - playerSettings.skipChapterEnd, child: AudioSource.uri( @@ -263,7 +272,7 @@ class AudiobookPlayer extends AudioPlayer { /// seek forward to the next chapter void seekForward() { - seekToNext(); + seekInBook(currentChapter!.end + offset); // final index = _book!.chapters.indexOf(currentChapter!); // if (index < _book!.chapters.length - 1) { // 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 Future seekToNext() { if (_currentIndex >= availableTracks!) { @@ -290,23 +323,6 @@ class AudiobookPlayer extends AudioPlayer { 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 Duration get positionInBook { if (_book == null) { diff --git a/shelfsdk b/shelfsdk index 4f19af2..e1848a4 160000 --- a/shelfsdk +++ b/shelfsdk @@ -1 +1 @@ -Subproject commit 4f19af242158bfb58f0b6893af9a11201a7b638a +Subproject commit e1848a42c27257146015a33e9427f197f522fe03