想在单个页面中添加多个 videoview
want to add multiple videoview in single page
所以,基本上我想在单个页面中添加多个视频。我尝试添加它仍然不是 working.there 是一些 bug.Bcoz 当我 运行 应用程序没有 error.I 尝试使用代码进行试验仍然没有 working.I 附上了我的 bvideos.xml 和相应的 java 文件。
这是我的 bvideos.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();
}
}
这是我的 bvideos.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>
您缺少 start();称呼。
尝试添加
videoView.start();
之后
videoView.setVideoURI(uri);
所以,基本上我想在单个页面中添加多个视频。我尝试添加它仍然不是 working.there 是一些 bug.Bcoz 当我 运行 应用程序没有 error.I 尝试使用代码进行试验仍然没有 working.I 附上了我的 bvideos.xml 和相应的 java 文件。
这是我的 bvideos.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();
}
}
这是我的 bvideos.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>
您缺少 start();称呼。 尝试添加
videoView.start();
之后
videoView.setVideoURI(uri);