Arianna Garaglia
Arianna Garaglia

Reputation: 21

mediacontroller not anchored to video frame layout

I'm trying to view videos in my app, but the problem is that the media controller doesn't stay docked to the video. In fact, if I scroll down the page, the media controller of the first video is located on the buttons

enter image description here

the code of the adapter is this:

public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) {
        String videoURL = videoURLs.get(position);

        VideoView videoView = holder.videoView;
        FrameLayout customMediaController = holder.customMediaController;

        // crea un mediaController personalizzato
        MediaController mediaController = new MediaController(holder.itemView.getContext());
        // collega la VideoView al MediaController
        mediaController.setAnchorView(videoView);
        // imposta il MediaController per la VideoView
        videoView.setMediaController(mediaController);

        // gestione manuale della posizione del MediaController
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT
        );
        layoutParams.gravity = Gravity.CENTER;
        customMediaController.setLayoutParams(layoutParams);

        .......
    } 

the code of the xml file is this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp">

    <!-- Pulsante Play -->
    <Button
        android:id="@+id/playButton"
        android:layout_width="@dimen/larghezza_bottone_piccolo"
        android:layout_height="@dimen/altezza_bottone_piccolo"
        android:text="@string/avvia"
        android:layout_marginTop="3dp"
        android:layout_marginStart="50dp" />

    <FrameLayout
        android:id="@+id/video_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/playButton">

        <VideoView
            android:id="@+id/videoView"
            android:layout_width="300dp"
            android:layout_height="300dp"
            />

        <FrameLayout
            android:id="@+id/custom_media_controller"
            android:layout_width="300dp"
            android:layout_height="300dp">
        </FrameLayout>
    </FrameLayout>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/deleteButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/delete_icon"
        android:contentDescription="@string/elimina"
        android:layout_marginTop="3dp"
        android:layout_marginStart="20dp"
        android:layout_toRightOf="@+id/playButton"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/downloadButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/baseline_download_24"
        android:contentDescription="@string/download"
        android:layout_marginTop="3dp"
        android:layout_toRightOf="@+id/deleteButton"
        android:layout_marginStart="20dp" />

</RelativeLayout>

I can't solve this problem, i've tried so many things

Upvotes: 1

Views: 18

Answers (0)

Related Questions