Skip to content

Commit

Permalink
Merge pull request #1358 from ISO-B/fix_check_files_before_playing
Browse files Browse the repository at this point in the history
Ensure that there is files available before playing local content
  • Loading branch information
advplyr authored Nov 4, 2024
2 parents 22529fc + 11804d1 commit 38bb5af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -78,6 +79,27 @@ class LocalLibraryItem(
}
}

@JsonIgnore
fun hasTracks(episode:PodcastEpisode?): Boolean {
var audioTracks = media.getAudioTracks() as MutableList<AudioTrack>
if (episode != null) { // Get podcast episode audio track
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
}

@JsonIgnore
fun getPlaybackSession(episode:PodcastEpisode?, deviceInfo:DeviceInfo):PlaybackSession {
val localEpisodeId = episode?.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand Down

0 comments on commit 38bb5af

Please sign in to comment.