mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-03 01:24:37 +02:00
Update:Syncing playback time when media item is open in player
This commit is contained in:
parent
b4bf10d409
commit
ff4f8324e7
25 changed files with 149 additions and 177 deletions
|
@ -305,9 +305,9 @@ data class PodcastEpisode(
|
|||
.setSubtitle(libraryItemDescription.title)
|
||||
.setExtras(extras)
|
||||
|
||||
libraryItemDescription.iconBitmap?.let {
|
||||
mediaDescriptionBuilder.setIconBitmap(it)
|
||||
}
|
||||
// libraryItemDescription.iconBitmap?.let {
|
||||
// mediaDescriptionBuilder.setIconBitmap(it)
|
||||
// }
|
||||
|
||||
return mediaDescriptionBuilder.build()
|
||||
}
|
||||
|
|
|
@ -110,17 +110,17 @@ class LocalLibraryItem(
|
|||
override fun getMediaDescription(progress:MediaProgressWrapper?, ctx:Context?): MediaDescriptionCompat {
|
||||
val coverUri = getCoverUri()
|
||||
|
||||
var bitmap:Bitmap? = null
|
||||
if (coverContentUrl != null) {
|
||||
ctx?.let {
|
||||
bitmap = if (Build.VERSION.SDK_INT < 28) {
|
||||
MediaStore.Images.Media.getBitmap(it.contentResolver, coverUri)
|
||||
} else {
|
||||
val source: ImageDecoder.Source = ImageDecoder.createSource(it.contentResolver, coverUri)
|
||||
ImageDecoder.decodeBitmap(source)
|
||||
}
|
||||
}
|
||||
}
|
||||
// var bitmap:Bitmap? = null
|
||||
// if (coverContentUrl != null) {
|
||||
// ctx?.let {
|
||||
// bitmap = if (Build.VERSION.SDK_INT < 28) {
|
||||
// MediaStore.Images.Media.getBitmap(it.contentResolver, coverUri)
|
||||
// } else {
|
||||
// val source: ImageDecoder.Source = ImageDecoder.createSource(it.contentResolver, coverUri)
|
||||
// ImageDecoder.decodeBitmap(source)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
val extras = Bundle()
|
||||
extras.putLong(
|
||||
|
@ -156,9 +156,9 @@ class LocalLibraryItem(
|
|||
.setSubtitle(authorName)
|
||||
.setExtras(extras)
|
||||
|
||||
bitmap?.let {
|
||||
mediaDescriptionBuilder.setIconBitmap(bitmap)
|
||||
}
|
||||
// bitmap?.let {
|
||||
// mediaDescriptionBuilder.setIconBitmap(bitmap)
|
||||
// }
|
||||
|
||||
return mediaDescriptionBuilder.build()
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.audiobookshelf.app.data
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.ImageDecoder
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import android.support.v4.media.MediaMetadataCompat
|
||||
import com.audiobookshelf.app.BuildConfig
|
||||
import com.audiobookshelf.app.R
|
||||
|
@ -168,16 +165,16 @@ class PlaybackSession(
|
|||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, getCoverUri().toString())
|
||||
|
||||
// Local covers get bitmap
|
||||
if (localLibraryItem?.coverContentUrl != null) {
|
||||
val bitmap = if (Build.VERSION.SDK_INT < 28) {
|
||||
MediaStore.Images.Media.getBitmap(ctx.contentResolver, getCoverUri())
|
||||
} else {
|
||||
val source: ImageDecoder.Source = ImageDecoder.createSource(ctx.contentResolver, getCoverUri())
|
||||
ImageDecoder.decodeBitmap(source)
|
||||
}
|
||||
metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap)
|
||||
metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
|
||||
}
|
||||
// if (localLibraryItem?.coverContentUrl != null) {
|
||||
// val bitmap = if (Build.VERSION.SDK_INT < 28) {
|
||||
// MediaStore.Images.Media.getBitmap(ctx.contentResolver, getCoverUri())
|
||||
// } else {
|
||||
// val source: ImageDecoder.Source = ImageDecoder.createSource(ctx.contentResolver, getCoverUri())
|
||||
// ImageDecoder.decodeBitmap(source)
|
||||
// }
|
||||
// metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap)
|
||||
// metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
|
||||
// }
|
||||
|
||||
return metadataBuilder.build()
|
||||
}
|
||||
|
|
|
@ -215,7 +215,6 @@ class MediaProgressSyncer(val playerNotificationService: PlayerNotificationServi
|
|||
val listeningTimeToAdd = diffSinceLastSync / 1000L
|
||||
|
||||
val syncData = MediaProgressSyncData(listeningTimeToAdd,currentPlaybackDuration,currentTime)
|
||||
|
||||
currentPlaybackSession?.syncData(syncData)
|
||||
|
||||
if (currentPlaybackSession?.progress?.isNaN() == true) {
|
||||
|
@ -243,11 +242,6 @@ class MediaProgressSyncer(val playerNotificationService: PlayerNotificationServi
|
|||
// Send sync to server also if connected to this server and local item belongs to this server
|
||||
if (hasNetworkConnection && shouldSyncServer && !it.libraryItemId.isNullOrEmpty() && it.serverConnectionConfigId != null && DeviceManager.serverConnectionConfig?.id == it.serverConnectionConfigId) {
|
||||
apiHandler.sendLocalProgressSync(it) { syncSuccess, errorMsg ->
|
||||
Log.d(
|
||||
tag,
|
||||
"Local progress sync data sent to server $currentDisplayTitle for time $currentTime"
|
||||
)
|
||||
|
||||
if (syncSuccess) {
|
||||
failedSyncs = 0
|
||||
playerNotificationService.alertSyncSuccess()
|
||||
|
|
|
@ -4,9 +4,7 @@ import android.annotation.SuppressLint
|
|||
import android.app.*
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.ImageDecoder
|
||||
import android.hardware.Sensor
|
||||
import android.hardware.SensorManager
|
||||
import android.net.ConnectivityManager
|
||||
|
@ -14,7 +12,6 @@ import android.net.Network
|
|||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkRequest
|
||||
import android.os.*
|
||||
import android.provider.MediaStore
|
||||
import android.provider.Settings
|
||||
import android.support.v4.media.MediaBrowserCompat
|
||||
import android.support.v4.media.MediaDescriptionCompat
|
||||
|
@ -292,18 +289,18 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
return MediaDescriptionCompat.Builder().build()
|
||||
}
|
||||
|
||||
val coverUri = currentPlaybackSession!!.getCoverUri()
|
||||
var coverUri = currentPlaybackSession!!.getCoverUri()
|
||||
|
||||
var bitmap:Bitmap? = null
|
||||
// var bitmap:Bitmap? = null
|
||||
// Local covers get bitmap
|
||||
if (currentPlaybackSession!!.localLibraryItem?.coverContentUrl != null) {
|
||||
bitmap = if (Build.VERSION.SDK_INT < 28) {
|
||||
MediaStore.Images.Media.getBitmap(ctx.contentResolver, coverUri)
|
||||
} else {
|
||||
val source: ImageDecoder.Source = ImageDecoder.createSource(ctx.contentResolver, coverUri)
|
||||
ImageDecoder.decodeBitmap(source)
|
||||
}
|
||||
}
|
||||
// if (currentPlaybackSession!!.localLibraryItem?.coverContentUrl != null) {
|
||||
// bitmap = if (Build.VERSION.SDK_INT < 28) {
|
||||
// MediaStore.Images.Media.getBitmap(ctx.contentResolver, coverUri)
|
||||
// } else {
|
||||
// val source: ImageDecoder.Source = ImageDecoder.createSource(ctx.contentResolver, coverUri)
|
||||
// ImageDecoder.decodeBitmap(source)
|
||||
// }
|
||||
// }
|
||||
|
||||
// Fix for local images crashing on Android 11 for specific devices
|
||||
// https://stackoverflow.com/questions/64186578/android-11-mediastyle-notification-crash/64232958#64232958
|
||||
|
@ -325,9 +322,9 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
.setTitle(currentPlaybackSession!!.displayTitle)
|
||||
.setIconUri(coverUri)
|
||||
|
||||
bitmap?.let {
|
||||
mediaDescriptionBuilder.setIconBitmap(it)
|
||||
}
|
||||
// bitmap?.let {
|
||||
// mediaDescriptionBuilder.setIconBitmap(it)
|
||||
// }
|
||||
|
||||
return mediaDescriptionBuilder.build()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue