mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
This commit is contained in:
parent
7721afc116
commit
b0c9f29d90
2 changed files with 16 additions and 25 deletions
|
@ -5,9 +5,6 @@ import android.graphics.Bitmap
|
|||
import android.net.Uri
|
||||
import android.support.v4.media.session.MediaControllerCompat
|
||||
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.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
|
@ -62,26 +59,10 @@ class AbMediaDescriptionAdapter constructor(private val controller: MediaControl
|
|||
|
||||
private suspend fun resolveUriAsBitmap(uri: Uri): Bitmap? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
// 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 {
|
||||
Glide.with(playerNotificationService)
|
||||
.asBitmap()
|
||||
.load(urival)
|
||||
.load(uri)
|
||||
.placeholder(R.drawable.icon)
|
||||
.error(R.drawable.icon)
|
||||
.submit(NOTIFICATION_LARGE_ICON_SIZE, NOTIFICATION_LARGE_ICON_SIZE)
|
||||
|
|
|
@ -66,7 +66,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
private lateinit var transportControls:MediaControllerCompat.TransportControls
|
||||
|
||||
lateinit var mediaManager: MediaManager
|
||||
lateinit var apiHandler: ApiHandler
|
||||
private lateinit var apiHandler: ApiHandler
|
||||
|
||||
lateinit var mPlayer: ExoPlayer
|
||||
lateinit var currentPlayer:Player
|
||||
|
@ -75,7 +75,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
lateinit var sleepTimerManager:SleepTimerManager
|
||||
lateinit var mediaProgressSyncer:MediaProgressSyncer
|
||||
|
||||
private var notificationId = 10;
|
||||
private var notificationId = 10
|
||||
private var channelId = "audiobookshelf_channel"
|
||||
private var channelName = "Audiobookshelf Channel"
|
||||
|
||||
|
@ -100,7 +100,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
// Android Auto Media Browser Service
|
||||
if (SERVICE_INTERFACE == intent.action) {
|
||||
Log.d(tag, "Is Media Browser Service")
|
||||
return super.onBind(intent);
|
||||
return super.onBind(intent)
|
||||
}
|
||||
return binder
|
||||
}
|
||||
|
@ -245,11 +245,21 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
mediaSessionConnector = MediaSessionConnector(mediaSession)
|
||||
val queueNavigator: TimelineQueueNavigator = object : TimelineQueueNavigator(mediaSession) {
|
||||
override fun getMediaDescription(player: Player, windowIndex: Int): MediaDescriptionCompat {
|
||||
val coverUri = currentPlaybackSession!!.getCoverUri()
|
||||
|
||||
// Fix for local images crashing on Android 10 for specific devices
|
||||
// https://stackoverflow.com/questions/64186578/android-11-mediastyle-notification-crash/64232958#64232958
|
||||
ctx.grantUriPermission(
|
||||
"com.android.systemui",
|
||||
coverUri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
|
||||
return MediaDescriptionCompat.Builder()
|
||||
.setMediaId(currentPlaybackSession!!.id)
|
||||
.setTitle(currentPlaybackSession!!.displayTitle)
|
||||
.setSubtitle(currentPlaybackSession!!.displayAuthor)
|
||||
.setIconUri(currentPlaybackSession!!.getCoverUri()).build()
|
||||
.setIconUri(coverUri).build()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,7 +377,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
val libraryItemId = playbackSession.libraryItemId ?: "" // Must be true since direct play
|
||||
val episodeId = playbackSession.episodeId
|
||||
apiHandler.playLibraryItem(libraryItemId, episodeId, true, mediaPlayer) {
|
||||
Handler(Looper.getMainLooper()).post() {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
preparePlayer(it, true, null)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue