diff --git a/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java b/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java index 938640c5a..42415cf80 100644 --- a/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java +++ b/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java @@ -17,6 +17,7 @@ import androidx.annotation.Nullable; import androidx.lifecycle.DefaultLifecycleObserver; import androidx.lifecycle.LifecycleOwner; import androidx.media3.common.MediaItem; +import androidx.media3.common.Player; import androidx.media3.exoplayer.ExoPlayer; import com.bumptech.glide.Glide; @@ -35,7 +36,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.File; -public class CustomWallView extends FrameLayout implements DefaultLifecycleObserver { +public class CustomWallView extends FrameLayout implements DefaultLifecycleObserver, Player.Listener { private ViewWallBinding binding; private ExoPlayer player; @@ -62,6 +63,7 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser player = new ExoPlayer.Builder(App.get()).setRenderersFactory(ExoUtil.buildRenderersFactory(EXTENSION_RENDERER_MODE_ON)).setMediaSourceFactory(ExoUtil.buildMediaSourceFactory()).build(); player.setRepeatMode(ExoPlayer.REPEAT_MODE_ALL); player.setPlayWhenReady(true); + player.addListener(this); player.setVolume(0); } @@ -107,7 +109,6 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser private void loadVideo(File file) { binding.video.setPlayer(player); - binding.video.setVisibility(VISIBLE); binding.image.setImageDrawable(cache); player.setMediaItem(MediaItem.fromUri(Uri.fromFile(file))); player.prepare(); @@ -128,6 +129,11 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser else binding.image.setImageResource(R.drawable.wallpaper_1); } + @Override + public void onRenderedFirstFrame() { + binding.video.setVisibility(VISIBLE); + } + @Override public void onCreate(@NonNull LifecycleOwner owner) { EventBus.getDefault().register(this); diff --git a/app/src/main/res/layout/view_wall.xml b/app/src/main/res/layout/view_wall.xml index 347310e32..2f5cbc9aa 100644 --- a/app/src/main/res/layout/view_wall.xml +++ b/app/src/main/res/layout/view_wall.xml @@ -14,7 +14,6 @@ android:id="@+id/video" android:layout_width="match_parent" android:layout_height="match_parent" - app:keep_content_on_player_reset="true" app:resize_mode="zoom" app:shutter_background_color="@color/transparent" app:surface_type="texture_view"