我在VideoView上面放了一个百度的MapView,如果视频不播放的话,就是不调用VideoView的start方法,MapView能正常显示,一旦调用start方法,MapView就会变黑,只显示比例尺和缩放按钮。
布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/back_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/saber"/>
<com.seawolf.test.FullScreeVideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/yaw_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="yaw"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/pitch_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/yaw_text"
android:text="pitch"/>
<TextView
android:id="@+id/roll_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="roll"
android:layout_above="@id/pitch_text"/>
<com.seawolf.test.NavController
android:id="@+id/navController"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"/>
<com.baidu.mapapi.map.MapView
android:id="@+id/map"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/navController"
android:background="@color/white"/>
</RelativeLayout>
</FrameLayout>
public void init() {
back_image = (ImageView) findViewById(R.id.back_image);
mController = new MediaController(this);
mVideo = (VideoView) findViewById(R.id.video);
File video = new File("/storage/sdcard1/hd.mp4");
if(video.exists())
{
mVideo.setVideoPath(video.getAbsolutePath()); // ①
// 设置videoView与mController建立关联
mVideo.setMediaController(mController); // ②
// 设置mController与videoView建立关联
mController.setMediaPlayer(mVideo); // ③
// 让VideoView获取焦点
// mVideo.requestFocus();
mVideo.setVisibility(View.INVISIBLE);
}else Toast.makeText(MainActivity.this,"The Video is not exist.",Toast.LENGTH_SHORT).show();
mMapView = (MapView) findViewById(R.id.map);
mMapView.setVisibility(View.INVISIBLE);
navController = (NavController) findViewById(R.id.navController);
navController.setVisibility(View.INVISIBLE);
navController.setOnNavAndSpeedListener(new NavController.OnNavAndSpeedListener() {
@Override
public void onNavAndSpeed(float nav, float speed) {
Toast.makeText(MainActivity.this, "nav is " + nav + ",speed is " + speed, Toast.LENGTH_SHORT).show();
}
});
}
private void videoStart()
{
mVideo.setVisibility(View.VISIBLE);
mMapView.setVisibility(View.VISIBLE);
navController.setVisibility(View.VISIBLE);
// mVideo.start();
}
VideoView と MapView はどちらも SurfaceView として理解できます。
を試してください。VideoView を設定できます: setZOrderMediaOverlay(true);
参考:
リンク 1
リンク 2