Кастомизация PlayerView из androidx.media3

подскажите пожалуйста как кастомизировать PlayerView, чтобы отобразить кнопки управления, и DefaultTimeBar? Разметку и код ниже прикрепил. Если запустить activity, то вместо PlayerView отображается темный квадрат, не видно кастомных кнопок, таймбара.

exo.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <LinearLayout
        android:id="@+id/button_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        
        <Button
            android:id="@+id/previous_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Previous" />

        <Button
            android:id="@+id/play_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Play" />

        <Button
            android:id="@+id/pause_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pause" />

        <Button
            android:id="@+id/next_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Next" />

    </LinearLayout>
    
    <androidx.media3.ui.DefaultTimeBar
        android:id="@+id/time_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp" />

</FrameLayout>

Сам PlayerView

    <androidx.media3.ui.PlayerView
        android:id="@+id/player"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/song_player_margin_left"
        android:layout_marginTop="@dimen/song_player_margin_top"
        android:layout_marginRight="@dimen/song_player_margin_right"
        android:layout_marginBottom="@dimen/song_player_margin_bottom"
        ads:hide_on_touch="false"
        ads:show_timeout="0"
        app:controller_layout_id="@layout/exo"
        app:hide_on_touch="true"
        app:resize_mode="fixed_width"
        app:show_buffering="always"></androidx.media3.ui.PlayerView>

Класс AudiPlayer

public class AudioPlayer {
    public static ExoPlayer player;
    public static PlayerView playerView;

    public static void startPlayer(String path, Context context) {
        startLocalPlayer(path, context);
    }

    @OptIn(markerClass = UnstableApi.class)
    private static void startLocalPlayer(String path, Context context) {
        if (player != null) {
            player.stop();
        }

        Uri uri = Uri.parse(path);

        DataSource.Factory dataSourceFactory = new FileDataSource.Factory();

        DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);

        player = new ExoPlayer.Builder(context)
                .setTrackSelector(trackSelector)
                .build();

        MediaItem mediaItem = new MediaItem.Builder()
                .setUri(uri)
                .build();

        MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);

        player.setMediaSource(mediaSource);

        player.prepare();
        player.play();

        player.addListener(new Player.Listener() {
            @Override
            public void onPlayerError(@NonNull PlaybackException error) {
                player.stop();
                player.play();
            }
        });
    }

    @UnstableApi
    public static void setCustomPlayerView(PlayerView playerView) {
        playerView.setUseController(false);

        playerView.setPlayer(player);
        
        playerView.setControllerShowTimeoutMs(0);
        playerView.setControllerAutoShow(false);
        playerView.setControllerAutoShow(true);
    }

    public static void stopPlayer() {
        if (player != null) {
            player.stop();
        }
    }

}

В Activity

public class SongPlayerActivity extends AppCompatActivity {

    ActivitySongPlayerBinding binding;
    private String songPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySongPlayerBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        
        AudioPlayer.playerView = new PlayerView(this);
       
        songPath = "file://" + getIntent().getExtras().getString("path");

        showPlayerView();
    }

    @OptIn(markerClass = UnstableApi.class)
    private void showPlayerView() {
        AudioPlayer.startPlayer(songPath, "local", this);
        AudioPlayer.playerView = binding.player;
        AudioPlayer.setCustomPlayerView(AudioPlayer.playerView);
    }
}

Ответы (0 шт):