From 0b202bab43a04fa329c92cdfeb939bdd48b87b81 Mon Sep 17 00:00:00 2001 From: Xwilarg Date: Thu, 31 Oct 2024 20:32:36 +0100 Subject: [PATCH] Attempt to show album image --- .../com/example/euphonia/PlaybackService.kt | 1 - .../com/example/euphonia/ui/PlayFragment.kt | 21 ++++++++++++++++++- .../src/main/res/layout/player_controls.xml | 7 ++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/example/euphonia/PlaybackService.kt b/android/app/src/main/java/com/example/euphonia/PlaybackService.kt index 0394a6f..c3acb58 100644 --- a/android/app/src/main/java/com/example/euphonia/PlaybackService.kt +++ b/android/app/src/main/java/com/example/euphonia/PlaybackService.kt @@ -1,6 +1,5 @@ package com.example.euphonia -import android.content.Intent import androidx.media3.common.MediaItem import androidx.media3.exoplayer.ExoPlayer import androidx.media3.session.MediaSession diff --git a/android/app/src/main/java/com/example/euphonia/ui/PlayFragment.kt b/android/app/src/main/java/com/example/euphonia/ui/PlayFragment.kt index e0ccb05..10fd4c3 100644 --- a/android/app/src/main/java/com/example/euphonia/ui/PlayFragment.kt +++ b/android/app/src/main/java/com/example/euphonia/ui/PlayFragment.kt @@ -1,10 +1,15 @@ package com.example.euphonia.ui +import android.graphics.BitmapFactory import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.ImageView +import androidx.media3.common.MediaItem +import androidx.media3.common.Player +import androidx.media3.common.util.Log import androidx.media3.common.util.UnstableApi import androidx.media3.ui.PlayerView import com.example.euphonia.R @@ -28,7 +33,21 @@ class PlayFragment : Fragment() { pView.controllerFuture?.addListener( { - videoView.player = pView.controllerFuture!!.get() + val player = pView.controllerFuture!!.get() + videoView.player = player + player.addListener(object : Player.Listener { + override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) { + val view = pView.findViewById(R.id.exo_image) + if (view != null) { + view.setImageBitmap(null) + val bmp = BitmapFactory.decodeFile(mediaItem!!.mediaMetadata.artworkUri!!.path) + if (bmp != null) { + view.setImageBitmap(bmp) + Log.d("TEMPS", mediaItem!!.mediaMetadata.artworkUri!!.path.toString()) + } + } + } + }) }, MoreExecutors.directExecutor() ) diff --git a/android/app/src/main/res/layout/player_controls.xml b/android/app/src/main/res/layout/player_controls.xml index 2be2346..5ef7385 100644 --- a/android/app/src/main/res/layout/player_controls.xml +++ b/android/app/src/main/res/layout/player_controls.xml @@ -2,6 +2,12 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + - \ No newline at end of file