Tweak code

This commit is contained in:
vfsfitvnm
2022-06-17 15:27:12 +02:00
parent 2877009db4
commit c2db7042c4
4 changed files with 11 additions and 27 deletions

View File

@@ -103,7 +103,7 @@ class PlayerService : MediaSessionService(), MediaSession.Callback, MediaNotific
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
notificationThumbnailSize = (96 * resources.displayMetrics.density).roundToInt() notificationThumbnailSize = (256 * resources.displayMetrics.density).roundToInt()
createNotificationChannel() createNotificationChannel()
setMediaNotificationProvider(this) setMediaNotificationProvider(this)
@@ -288,15 +288,15 @@ class PlayerService : MediaSessionService(), MediaSession.Callback, MediaNotific
override fun onAddMediaItems( override fun onAddMediaItems(
mediaSession: MediaSession, mediaSession: MediaSession,
controller: MediaSession.ControllerInfo, controller: MediaSession.ControllerInfo,
mediaItems: MutableList<MediaItem> mediaItems: List<MediaItem>
): ListenableFuture<MutableList<MediaItem>> { ): ListenableFuture<List<MediaItem>> {
return Futures.immediateFuture( return Futures.immediateFuture(
mediaItems.map { mediaItem -> mediaItems.map { mediaItem ->
mediaItem.buildUpon() mediaItem.buildUpon()
.setUri(mediaItem.mediaId) .setUri(mediaItem.mediaId)
.setCustomCacheKey(mediaItem.mediaId) .setCustomCacheKey(mediaItem.mediaId)
.build() .build()
}.toMutableList() }
) )
} }
@@ -360,21 +360,12 @@ class PlayerService : MediaSessionService(), MediaSession.Callback, MediaNotific
R.drawable.play_skip_back, R.drawable.play_skip_back,
R.string.media3_controls_seek_to_previous_description, R.string.media3_controls_seek_to_previous_description,
Player.COMMAND_SEEK_TO_PREVIOUS Player.COMMAND_SEEK_TO_PREVIOUS
).run { ).addMediaAction(
if (mediaSession.player.playbackState == Player.STATE_ENDED || !mediaSession.player.playWhenReady) { if (mediaSession.player.playbackState == Player.STATE_ENDED || !mediaSession.player.playWhenReady) R.drawable.play else R.drawable.pause,
addMediaAction( if (mediaSession.player.playbackState == Player.STATE_ENDED || !mediaSession.player.playWhenReady) R.string.media3_controls_play_description else R.string.media3_controls_pause_description,
R.drawable.play, Player.COMMAND_PLAY_PAUSE
R.string.media3_controls_play_description, )
Player.COMMAND_PLAY_PAUSE .addMediaAction(
)
} else {
addMediaAction(
R.drawable.pause,
R.string.media3_controls_pause_description,
Player.COMMAND_PLAY_PAUSE
)
}
}.addMediaAction(
R.drawable.play_skip_forward, R.drawable.play_skip_forward,
R.string.media3_controls_seek_to_next_description, R.string.media3_controls_seek_to_next_description,
Player.COMMAND_SEEK_TO_NEXT Player.COMMAND_SEEK_TO_NEXT
@@ -405,9 +396,7 @@ class PlayerService : MediaSessionService(), MediaSession.Callback, MediaNotific
session: MediaSession, session: MediaSession,
action: String, action: String,
extras: Bundle extras: Bundle
): Boolean { ): Boolean = false
return false
}
private fun createNotificationChannel() { private fun createNotificationChannel() {
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

View File

@@ -90,7 +90,6 @@ fun PlayerSettingsScreen() {
LaunchedEffect(mediaController) { LaunchedEffect(mediaController) {
while (isActive) { while (isActive) {
println("mediaController: $mediaController")
sleepTimerMillisLeft = sleepTimerMillisLeft =
mediaController?.syncCommand(GetSleepTimerMillisLeftCommand) mediaController?.syncCommand(GetSleepTimerMillisLeftCommand)
?.takeIf { it.resultCode == SessionResult.RESULT_SUCCESS } ?.takeIf { it.resultCode == SessionResult.RESULT_SUCCESS }

View File

@@ -20,7 +20,6 @@ class YoutubePlayer(mediaController: MediaController) : PlayerState(mediaControl
var nextContinuation by mutableStateOf<Outcome<String?>>(Outcome.Initial) var nextContinuation by mutableStateOf<Outcome<String?>>(Outcome.Initial)
suspend fun process(): List<MediaItem> { suspend fun process(): List<MediaItem> {
println("process: ${nextContinuation.valueOrNull}")
val token = nextContinuation.valueOrNull val token = nextContinuation.valueOrNull
nextContinuation = Outcome.Loading nextContinuation = Outcome.Loading

View File

@@ -617,9 +617,6 @@ object YouTube {
thumbnail = renderer thumbnail = renderer
.thumbnail .thumbnail
.thumbnails .thumbnails
.also {
println(it)
}
.firstOrNull(), .firstOrNull(),
durationText = renderer durationText = renderer
.lengthText .lengthText