Navigation Drawer and VideoView in android

人盡茶涼 提交于 2019-12-04 22:45:39

@Atula I suggest you a simple solution for this....This is work Perfect

I attach the screenshot working properly....

Try this

Used this

  video_player_view.setZOrderMediaOverlay(true);

Instead Of

  video_view.setZOrderOnTop(true);

When you setZOrderOnTop(true) it will be on top of other Layout. In fact it Control whether the surface view's surface is placed on top of it window [see more].

I have a video in my tab which was not visible at first but I can hear sound.

Based on your comment you put other Layout on VideoView so you can't see VideoView But you hear the sound.

By turning Layout bound in phone:

Setting-> developer option -> show Layout bound

You can see what's going on in your Layouts. I guess you can't see VideoView because of those match_parents in your layout_height double check them ( e.g: put 50dp for each of them) and your problem will be fixed.

Also make root Layout match_parent instead of wrap_content. it's not solve the problem but its much better.

Shark

After a few comments, the OP wanted to see some code.

Ok, let's try something like this:

private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;

protected void onResume() {
    drawer.addDrawerListener(toggle);
    toggle.syncState();
}

protected void onPause() {
    drawer.removeDrawerListener(toggle);
    toggle.syncState();
}

protected void onCreate(Bundle saveInstanceState) {

    toggle = new ActionBarDrawerToggle(this, drawer, 
        toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
            public void onDrawerClosed(View view) {
                Log.d(TAG, "--> ActionBarDrawerToggle::onDrawerClosed
                    (view=" + view + ")");
                syncActionBarArrowState();
                //call videoView.setZOrderOnTop(true) so it's over everything
            }

            public void onDrawerOpened(View drawerView) {

                Log.d(TAG, "--> ActionBarDrawerToggle::onDrawerOpened
                    (drawerView=" + drawerView + ")");
                toggle.setDrawerIndicatorEnabled(true);
                //call videoView.setZOrderOnTop(false) so it's NOT over the drawer
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                 super.onDrawerSlide(drawerView, 0);
                 //call videoView.setZOrderOnTop(false) 
                 //so it's not over the drawer being pulled out
            }
        };
}

Did you try to use TextureView instead VideoView?
ViedoView is well known as bug prone view.

I wrote frame-video-view which (among other things) simplifies using TextureView as a video player.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!