Tweak PlayerService code
This commit is contained in:
@@ -104,7 +104,6 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.cancellable
|
import kotlinx.coroutines.flow.cancellable
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
@@ -298,16 +297,13 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
|
|||||||
|
|
||||||
if (totalPlayTimeMs > 30000) {
|
if (totalPlayTimeMs > 30000) {
|
||||||
query {
|
query {
|
||||||
// THANKS, EXOPLAYER
|
Database.insert(
|
||||||
if (runBlocking { Database.song(mediaItem.mediaId).first() } != null) {
|
Event(
|
||||||
Database.insert(
|
songId = mediaItem.mediaId,
|
||||||
Event(
|
timestamp = System.currentTimeMillis(),
|
||||||
songId = mediaItem.mediaId,
|
playTime = totalPlayTimeMs
|
||||||
timestamp = System.currentTimeMillis(),
|
|
||||||
playTime = totalPlayTimeMs
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,20 +318,6 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
|
|||||||
} else if (mediaItem.mediaMetadata.artworkUri == bitmapProvider.lastUri) {
|
} else if (mediaItem.mediaMetadata.artworkUri == bitmapProvider.lastUri) {
|
||||||
bitmapProvider.listener?.invoke(bitmapProvider.lastBitmap)
|
bitmapProvider.listener?.invoke(bitmapProvider.lastBitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On playlist changed, we refresh the mediaSession queue
|
|
||||||
// if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED) {
|
|
||||||
// mediaSession.setQueue(player.currentTimeline.mediaItems.mapIndexed { index, it ->
|
|
||||||
// MediaSession.QueueItem(
|
|
||||||
// MediaDescription.Builder()
|
|
||||||
// .setMediaId(it.mediaId)
|
|
||||||
// .setTitle(it.mediaMetadata.title)
|
|
||||||
// .setSubtitle(it.mediaMetadata.artist)
|
|
||||||
// .setIconUri(it.mediaMetadata.artworkUri)
|
|
||||||
// .build(), index.toLong()
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun maybeRecoverPlaybackError() {
|
private fun maybeRecoverPlaybackError() {
|
||||||
@@ -483,10 +465,6 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
|
|||||||
MediaMetadata.METADATA_KEY_ALBUM,
|
MediaMetadata.METADATA_KEY_ALBUM,
|
||||||
player.currentMediaItem?.mediaMetadata?.albumTitle
|
player.currentMediaItem?.mediaMetadata?.albumTitle
|
||||||
)
|
)
|
||||||
// .putBitmap(
|
|
||||||
// MediaMetadata.METADATA_KEY_ALBUM_ART,
|
|
||||||
// if (isShowingThumbnailInLockscreen) bitmapProvider.bitmap else null
|
|
||||||
// )
|
|
||||||
.putLong(MediaMetadata.METADATA_KEY_DURATION, player.duration)
|
.putLong(MediaMetadata.METADATA_KEY_DURATION, player.duration)
|
||||||
.build().let(mediaSession::setMetadata)
|
.build().let(mediaSession::setMetadata)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user