您的位置:首页技术文章
文章详情页

android - VideoView与百度Map冲突

浏览:88日期:2022-10-06 10:32:11

问题描述

我在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: android:layout_width='match_parent' android:layout_height='match_parent' android:background='@drawable/saber'/><com.seawolf.test.FullScreeVideoView android: 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'> <TextViewandroid: 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' /> <TextViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_above='@id/yaw_text'android:text='pitch'/> <TextViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:text='roll'android:layout_above='@id/pitch_text'/> <com.seawolf.test.NavControllerandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_alignParentBottom='true'android:layout_alignParentLeft='true'/> <com.baidu.mapapi.map.MapViewandroid: 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(); }

问题解答

回答1:

VideoView和MapView都可以理解为SurfaceView。你可以给VideoView设置:setZOrderMediaOverlay(true);试试

参考:链接1链接2

标签: 百度
相关文章: