mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-03 01:24:37 +02:00
Fix:Check local cover image read permission and remove cover #35
This commit is contained in:
parent
72732025ae
commit
080a08aebc
2 changed files with 31 additions and 7 deletions
|
@ -89,6 +89,11 @@ class AudiobookStreamData {
|
|||
}
|
||||
}
|
||||
|
||||
fun clearCover() {
|
||||
coverUri = Uri.EMPTY
|
||||
cover = ""
|
||||
}
|
||||
|
||||
fun getMediaMetadataCompat():MediaMetadataCompat {
|
||||
var metadataBuilder = MediaMetadataCompat.Builder()
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
|
||||
|
@ -99,10 +104,10 @@ class AudiobookStreamData {
|
|||
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, series)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id)
|
||||
|
||||
if (cover != "") {
|
||||
metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, cover)
|
||||
metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, cover)
|
||||
}
|
||||
// if (cover != "") {
|
||||
// metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, cover)
|
||||
// metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, cover)
|
||||
// }
|
||||
return metadataBuilder.build()
|
||||
}
|
||||
|
||||
|
@ -114,9 +119,9 @@ class AudiobookStreamData {
|
|||
.setAlbumArtist(author)
|
||||
.setSubtitle(author)
|
||||
|
||||
if (coverUri != Uri.EMPTY) {
|
||||
metadataBuilder.setArtworkUri(coverUri)
|
||||
}
|
||||
// if (coverUri != Uri.EMPTY) {
|
||||
// metadataBuilder.setArtworkUri(coverUri)
|
||||
// }
|
||||
if (playlistUri != Uri.EMPTY) {
|
||||
metadataBuilder.setMediaUri(playlistUri)
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@ import android.util.Log
|
|||
import android.view.KeyEvent
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.media.MediaBrowserServiceCompat
|
||||
import androidx.media.utils.MediaConstants
|
||||
import com.anggrayudi.storage.file.isExternalStorageDocument
|
||||
import com.getcapacitor.Bridge
|
||||
import com.getcapacitor.JSObject
|
||||
import com.google.android.exoplayer2.*
|
||||
|
@ -670,6 +672,23 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
Log.d(tag, "Init Player audiobook already playing")
|
||||
}
|
||||
|
||||
// Issue with onenote plus crashing when using local cover art. https://github.com/advplyr/audiobookshelf-app/issues/35
|
||||
if (currentAudiobookStreamData?.coverUri != null && currentAudiobookStreamData?.isLocal == true) {
|
||||
try {
|
||||
Log.d(tag, "CHECKING COVER ${currentAudiobookStreamData?.coverUri}")
|
||||
var file = DocumentFile.fromTreeUri(ctx, currentAudiobookStreamData!!.coverUri)
|
||||
Log.d(tag, "GOT FILE ${file?.name} | ${file?.type} | Can Read: ${file?.canRead()} |isExternalStorageDocument: ${file?.isExternalStorageDocument}")
|
||||
if (file?.canRead() !== true) {
|
||||
Log.d(tag, "Invalid cover: no read access")
|
||||
currentAudiobookStreamData?.clearCover()
|
||||
}
|
||||
} catch(e:Exception) {
|
||||
Log.d(tag, "Invalid cover: Failed to read local cover file $e")
|
||||
currentAudiobookStreamData?.clearCover()
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
var metadata = currentAudiobookStreamData!!.getMediaMetadataCompat()
|
||||
mediaSession.setMetadata(metadata)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue