Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Canvas: TextureView inflated with the controller off, no black flash on the first opening
kota-zo460ff19221ef
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.ktindex 116d0331..72ca719b 100644--- a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt@@ -1312,23 +1312,10 @@ private fun CanvasVideo(url: String, playing: Boolean, onFirstFrame: () -> Unit,// factory runs once; a new track's clip gets a new player, so rebind it here.update = { it.player = exo },factory = { ctx ->- androidx.media3.ui.PlayerView(ctx).apply {- // Strip ALL chrome: no controller, no buffering spinner, and no- // artwork/placeholder icon (that "play icon" overlay) — just video.- // The controller goes off before the player is set: a player given to a- // view with its controller on shows the prev / next buttons for a moment.- useController = false- controllerAutoShow = false- setShowBuffering(androidx.media3.ui.PlayerView.SHOW_BUFFERING_NEVER)+ // Inflated: the surface type (texture view) can only be set from XML.+ (android.view.LayoutInflater.from(ctx).inflate(R.layout.canvas_player_view, null) as androidx.media3.ui.PlayerView).apply {setArtworkDisplayMode(androidx.media3.ui.PlayerView.ARTWORK_DISPLAY_MODE_OFF)- setUseArtwork(false)setDefaultArtwork(null)- hideController()- resizeMode = androidx.media3.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM- setBackgroundColor(android.graphics.Color.TRANSPARENT)- // Until a clip's first frame, show the screen behind, not a black shutter.- setShutterBackgroundColor(android.graphics.Color.TRANSPARENT)- setKeepContentOnPlayerReset(true)player = exo}},diff --git a/base/app/src/main/res/layout/canvas_player_view.xml b/base/app/src/main/res/layout/canvas_player_view.xmlnew file mode 100644index 00000000..21ffbd82--- /dev/null+++ b/base/app/src/main/res/layout/canvas_player_view.xml@@ -0,0 +1,17 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The Canvas clip. A TextureView, not the default SurfaceView: a SurfaceView shows black+ until the first frame (a flash over the screen behind), and the controller is off from+ inflation, so its previous / next buttons never appear. -->+<androidx.media3.ui.PlayerView xmlns:android="http://schemas.android.com/apk/res/android"+ xmlns:app="http://schemas.android.com/apk/res-auto"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:background="@android:color/transparent"+ app:surface_type="texture_view"+ app:use_controller="false"+ app:auto_show="false"+ app:show_buffering="never"+ app:use_artwork="false"+ app:resize_mode="zoom"+ app:shutter_background_color="@android:color/transparent"+ app:keep_content_on_player_reset="true" />