mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-27 13:54:01 +02:00
Merge pull request #1358 from ISO-B/fix_check_files_before_playing
Ensure that there is files available before playing local content
This commit is contained in:
@@ -18,6 +18,7 @@ import com.audiobookshelf.app.device.DeviceManager
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
import com.audiobookshelf.app.player.PLAYMETHOD_LOCAL
|
import com.audiobookshelf.app.player.PLAYMETHOD_LOCAL
|
||||||
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
@@ -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
|
@JsonIgnore
|
||||||
fun getPlaybackSession(episode:PodcastEpisode?, deviceInfo:DeviceInfo):PlaybackSession {
|
fun getPlaybackSession(episode:PodcastEpisode?, deviceInfo:DeviceInfo):PlaybackSession {
|
||||||
val localEpisodeId = episode?.id
|
val localEpisodeId = episode?.id
|
||||||
|
|||||||
@@ -198,6 +198,9 @@ class AbsAudioPlayer : Plugin() {
|
|||||||
return call.resolve(JSObject("{\"error\":\"Podcast episode not found\"}"))
|
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 {
|
Handler(Looper.getMainLooper()).post {
|
||||||
Log.d(tag, "prepareLibraryItem: Preparing Local Media item ${jacksonMapper.writeValueAsString(it)}")
|
Log.d(tag, "prepareLibraryItem: Preparing Local Media item ${jacksonMapper.writeValueAsString(it)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user