要在单个页面中添加多个视频视图吗

thigvfpy  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(326)

所以,基本上我想在一个页面上添加多个视频。我试着添加它仍然不起作用。有一些bug.bcoz当我运行应用程序时没有错误。我试着尝试代码仍然不起作用。我附上了我的bvideos.xml和相应的java文件。
这是我的bvidos.java文件

public class bvideos extends AppCompatActivity {

    private VideoView videoView;
    private MediaController mediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bvideos);

       /* VideoView videoView  = findViewById(R.id.video_view1);
        videoView.setVideoPath("android.resource://"+getPackageName()+"/"+R.raw.bvideo1);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        videoView.setMediaController(mediaController);*/

        Button photo = (Button) findViewById(R.id.bphoto);
        photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent y = new Intent(bvideos.this, mainpage.class);
                startActivity(y);

            }
        });

        videoView = findViewById(R.id.video_view1);

        /*String fullScreen =  getIntent().getStringExtra("fullScreenInd");
        if("y".equals(fullScreen)){
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getSupportActionBar().hide();
        }*/

        Uri videoUri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.bvideo1);

        videoView.setVideoURI(videoUri);

        mediaController = new FullScreenMediaController(this);
        mediaController.setAnchorView(videoView);

        videoView.setMediaController(mediaController);
        videoView.start();

        videoView = findViewById(R.id.video_view2);

        /*String fullScreen =  getIntent().getStringExtra("fullScreenInd");
        if("y".equals(fullScreen)){
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getSupportActionBar().hide();
        }*/

        Uri videoUri1 = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.bvideo2);

        videoView.setVideoURI(videoUri1);

        mediaController = new FullScreenMediaController(this);
        mediaController.setAnchorView(videoView);

        videoView.setMediaController(mediaController);
        videoView.start();

    }
}

这是我的bvidos.xml文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".bvideos">

    <LinearLayout
        android:orientation="vertical"
        android:background="@color/Pink"
        android:weightSum="10"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2">

            <TextView
                android:id="@+id/TextView"
                android:layout_width="950dp"
                android:layout_height="550dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="5dp"
                android:layout_marginBottom="0dp"
                android:alpha="0.5"
                android:background="@color/purple_200"
                android:text="     BEGINNERS CALLIGRAPHY"
                android:textAllCaps="false"
                android:textColor="@color/DarkBlue"
                android:textSize="25sp"
                android:textStyle="bold|italic" />

            <Button
                android:id="@+id/bphoto"
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="210dp"
                android:layout_marginBottom="7dp"
                android:text="PHOTOS"
                android:textSize="20dp"
                android:background="@color/white"
                android:textColor="@color/purple_700"/>

            <Button
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="52dp"
                android:layout_marginBottom="7dp"
                android:text="VIDEOS"
                android:textSize="20dp"
                android:background="@color/white"
                android:textColor="@color/purple_700"/>

        </RelativeLayout>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="20dp"
            android:layout_margin="10dp">

            <VideoView
                android:id="@+id/video_view1"
                android:layout_width="match_parent"
                android:layout_height="242dp" />

        </FrameLayout>

        <TextView
            android:layout_width="374dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:text="Brush Calligraphy Alphabets for Beginners| Basic Strokes| Lowercase Alphabets "
            android:textSize="20dp" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_margin="10dp">

            <VideoView
                android:id="@+id/video_view2"
                android:layout_width="match_parent"
                android:layout_height="232dp" />

        </FrameLayout>

        <TextView
            android:layout_width="374dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:text="How to Gothic Calligraphy Capital and Small Letters From A to Z |Blackletters Calligraphy "
            android:textSize="20dp" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_margin="10dp">

            <VideoView
                android:id="@+id/video_view3"
                android:layout_width="match_parent"
                android:layout_height="232dp" />

        </FrameLayout>

    </LinearLayout>

</ScrollView>
rta7y2nd

rta7y2nd1#

你错过了开始();打电话。尝试添加

videoView.start();

之后

videoView.setVideoURI(uri);

相关问题