From 3364f60d32bf88a10373216b98a73d4124c6c9a4 Mon Sep 17 00:00:00 2001 From: Ivan Agosto Date: Sat, 11 May 2024 13:51:16 -0600 Subject: [PATCH] Update exo player with better UX --- .../agosto/p2play/ReproductorActivity.kt | 16 ++++ .../res/drawable/ic_baseline_settings_24.xml | 5 + .../main/res/layout/activity_reproductor.xml | 8 +- .../res/layout/custom_player_controls.xml | 92 ++++++++++--------- 4 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_settings_24.xml diff --git a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt index 0735b8f..fe71c0c 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.media3.common.MediaItem import androidx.media3.common.MediaMetadata +import androidx.media3.common.Player import androidx.media3.exoplayer.DefaultLoadControl import androidx.media3.exoplayer.ExoPlayer import androidx.media3.exoplayer.upstream.DefaultAllocator @@ -32,6 +33,7 @@ import kotlinx.android.synthetic.main.comment_component.commentaryBtn import kotlinx.android.synthetic.main.comment_component.commentaryLayout import kotlinx.android.synthetic.main.comment_component.commentaryText import kotlinx.android.synthetic.main.comment_component.userImgCom +import kotlinx.android.synthetic.main.custom_player_controls.view.exo_controls import org.libre.agosto.p2play.adapters.CommentariesAdapter import org.libre.agosto.p2play.ajax.Actions import org.libre.agosto.p2play.ajax.Comments @@ -151,9 +153,23 @@ class ReproductorActivity : AppCompatActivity() { .setSeekForwardIncrementMs(10000) .setLoadControl(loadControl).build() } + player = PlaybackSingleton.player!! exoPlayer.player = player + player.addListener( + object : Player.Listener { + override fun onPlaybackStateChanged(playbackState: Int) { + super.onPlaybackStateChanged(playbackState) + if (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_IDLE) { + exoPlayer.exo_controls.visibility = View.INVISIBLE + } else if (playbackState == Player.STATE_READY) { + exoPlayer.exo_controls.visibility = View.VISIBLE + } + } + } + ) + println("----- video --------") println(videoPlayback.streamingData?.playlistUrl) diff --git a/app/src/main/res/drawable/ic_baseline_settings_24.xml b/app/src/main/res/drawable/ic_baseline_settings_24.xml new file mode 100644 index 0000000..094732d --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_settings_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index ad370a8..2cc533a 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -39,6 +39,7 @@ android:layout_height="match_parent" android:background="#000" app:use_controller="true" + app:show_buffering="always" app:controller_layout_id="@layout/custom_player_controls" app:player_layout_id="@layout/exo_player_view"/> @@ -73,9 +74,12 @@ android:id="@+id/exoPlayer" android:layout_width="match_parent" android:layout_height="205dp" - app:use_controller="true" + app:auto_show="true" + app:show_buffering="always" app:controller_layout_id="@layout/custom_player_controls" - app:player_layout_id="@layout/exo_player_view"/> + app:surface_type="surface_view" + app:use_controller="true" + app:repeat_toggle_modes="none"/> + android:layout_height="match_parent" + android:background="#44000000"> + + + android:layout_width="35dp" + android:layout_height="35dp" + android:src="@drawable/ic_replay_10_24" /> + android:layout_width="43dp" + android:layout_height="43dp" + android:layout_marginHorizontal="30dp" /> + android:layout_width="35dp" + android:layout_height="35dp" + android:src="@drawable/ic_forward_10_24" /> + + + + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="#fff" /> + + android:textColor="#CBCDC8" /> + - - - - - + android:textColor="#CBCDC8" /> + android:src="@drawable/ic_fullscreen_24" /> + - - \ No newline at end of file