mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-28 13:58:23 +02:00
Fix:Cover crashing when using in media notification. Convert content uri for local image to File and pass main activity context instead of player service context #35 #164
This commit is contained in:
parent
736e57fafd
commit
4fa6dd2616
2 changed files with 25 additions and 3 deletions
|
@ -5,6 +5,9 @@ import android.graphics.Bitmap
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.support.v4.media.session.MediaControllerCompat
|
import android.support.v4.media.session.MediaControllerCompat
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.documentfile.provider.DocumentFile
|
||||||
|
import com.anggrayudi.storage.file.getAbsolutePath
|
||||||
|
import com.anggrayudi.storage.file.toRawFile
|
||||||
import com.audiobookshelf.app.R
|
import com.audiobookshelf.app.R
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
@ -60,10 +63,25 @@ class AbMediaDescriptionAdapter constructor(private val controller: MediaControl
|
||||||
private suspend fun resolveUriAsBitmap(uri: Uri): Bitmap? {
|
private suspend fun resolveUriAsBitmap(uri: Uri): Bitmap? {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
// Block on downloading artwork.
|
// Block on downloading artwork.
|
||||||
|
val context = playerNotificationService.getContext()
|
||||||
|
|
||||||
|
// Fix attempt for #35 local cover crashing
|
||||||
|
// Convert content uri to a file and pass to Glide
|
||||||
|
var urival:Any = uri
|
||||||
|
if (uri.toString().startsWith("content:")) {
|
||||||
|
val imageDocFile = DocumentFile.fromSingleUri(context, uri)
|
||||||
|
Log.d(tag, "Converting local content url $uri to file with path ${imageDocFile?.getAbsolutePath(context)}")
|
||||||
|
val file = imageDocFile?.toRawFile(context)
|
||||||
|
file?.let {
|
||||||
|
Log.d(tag, "Using local file image instead of content uri ${it.absolutePath}")
|
||||||
|
urival = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Glide.with(playerNotificationService).applyDefaultRequestOptions(glideOptions)
|
Glide.with(context).applyDefaultRequestOptions(glideOptions)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(uri)
|
.load(urival)
|
||||||
.placeholder(R.drawable.icon)
|
.placeholder(R.drawable.icon)
|
||||||
.error(R.drawable.icon)
|
.error(R.drawable.icon)
|
||||||
.submit(NOTIFICATION_LARGE_ICON_SIZE, NOTIFICATION_LARGE_ICON_SIZE)
|
.submit(NOTIFICATION_LARGE_ICON_SIZE, NOTIFICATION_LARGE_ICON_SIZE)
|
||||||
|
@ -71,7 +89,7 @@ class AbMediaDescriptionAdapter constructor(private val controller: MediaControl
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|
||||||
Glide.with(playerNotificationService).applyDefaultRequestOptions(glideOptions)
|
Glide.with(context).applyDefaultRequestOptions(glideOptions)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(Uri.parse("android.resource://com.audiobookshelf.app/" + R.drawable.icon))
|
.load(Uri.parse("android.resource://com.audiobookshelf.app/" + R.drawable.icon))
|
||||||
.submit(NOTIFICATION_LARGE_ICON_SIZE, NOTIFICATION_LARGE_ICON_SIZE)
|
.submit(NOTIFICATION_LARGE_ICON_SIZE, NOTIFICATION_LARGE_ICON_SIZE)
|
||||||
|
|
|
@ -539,6 +539,10 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
||||||
return if(currentPlayer == castPlayer) "cast-player" else "exo-player"
|
return if(currentPlayer == castPlayer) "cast-player" else "exo-player"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getContext():Context {
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// MEDIA BROWSER STUFF (ANDROID AUTO)
|
// MEDIA BROWSER STUFF (ANDROID AUTO)
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue