From 8f181c74d4a3ad2ff7bf3e772f6e094cf733e17e Mon Sep 17 00:00:00 2001 From: ISO-B <3048685+ISO-B@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:51:29 +0200 Subject: [PATCH 1/2] Ensure that there is files available before playing local content --- .../com/audiobookshelf/app/data/LocalLibraryItem.kt | 10 ++++++++++ .../com/audiobookshelf/app/plugins/AbsAudioPlayer.kt | 3 +++ 2 files changed, 13 insertions(+) diff --git a/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt b/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt index c6a25cbd6..8717f6483 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt @@ -78,6 +78,16 @@ class LocalLibraryItem( } } + @JsonIgnore + fun hasTracks(episode:PodcastEpisode?): Boolean { + var audioTracks = media.getAudioTracks() as MutableList + if (episode != null) { // Get podcast episode audio track + episode.audioTrack?.let { at -> mutableListOf(at) }?.let { tracks -> audioTracks = tracks } + } + if (audioTracks.size == 0) return false + return true + } + @JsonIgnore fun getPlaybackSession(episode:PodcastEpisode?, deviceInfo:DeviceInfo):PlaybackSession { val localEpisodeId = episode?.id diff --git a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt index 25a423ba9..e51e2ee6a 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt @@ -198,6 +198,9 @@ class AbsAudioPlayer : Plugin() { return call.resolve(JSObject("{\"error\":\"Podcast episode not found\"}")) } } + if (!it.hasTracks(episode)) { + return call.resolve(JSObject("{\"error\":\"No audio files found on device. Download book again to fix.\"}")) + } Handler(Looper.getMainLooper()).post { Log.d(tag, "prepareLibraryItem: Preparing Local Media item ${jacksonMapper.writeValueAsString(it)}") From 11804d1cb83f802119e6d7ac2fb933ddf719ab79 Mon Sep 17 00:00:00 2001 From: ISO-B <3048685+ISO-B@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:54:02 +0200 Subject: [PATCH 2/2] Enhanced check for local audio tracks When check is triggered code now checks that are files really exists --- .../com/audiobookshelf/app/data/LocalLibraryItem.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt b/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt index 8717f6483..635c98f21 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/data/LocalLibraryItem.kt @@ -18,6 +18,7 @@ import com.audiobookshelf.app.device.DeviceManager import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.audiobookshelf.app.player.PLAYMETHOD_LOCAL +import java.io.File import java.util.* @JsonIgnoreProperties(ignoreUnknown = true) @@ -85,6 +86,17 @@ class LocalLibraryItem( episode.audioTrack?.let { at -> mutableListOf(at) }?.let { tracks -> audioTracks = tracks } } if (audioTracks.size == 0) return false + audioTracks.forEach { + // Check that metadata is not null + if (it.metadata === null) { + return false + } + // Check that file exists + val file = File(it.metadata!!.path) + if (!file.exists()) { + return false + } + } return true }