0

i have a FullScreen Activity for playing Video , Everything is going well until i tap the screen to view System Ui and Media Controller , but MediaController goes behind of NavigationBar and its very aweful,

please see these images to understand problem :

Device1 - Normal State

Device1 - and MediaController Visible

and there is my codes : MyActivity :

    public class ActivityPlayVideo4 extends Activity{

    public static final String KEY_VIDEO_URL = "videoUrl";
    String url;
    ProgressView pvLoading;

    private static final boolean AUTO_HIDE = true;

    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    private static final boolean TOGGLE_ON_CLICK = true;

    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    private SystemUiHider mSystemUiHider;

    private VideoView mVideoView;
    private MediaController mMediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

        setContentView(R.layout.activity_video_playing);


        try {
            url = getIntent().getExtras().getString(KEY_VIDEO_URL);
        } catch (Exception e) {
            url = "";
        }


        mVideoView = (VideoView) findViewById(R.id.videoView);

        // Set up an instance of SystemUiHider to control the system UI for
        // this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, mVideoView, HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (visible && AUTO_HIDE) {
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

        mVideoView.setOnCompletionListener(new PlayerOnCompleteVideo());
        mMediaController = new MediaController(this,false);
        mMediaController.setMediaPlayer(mVideoView);

        mVideoView.setMediaController(mMediaController);
        mVideoView.requestFocus();


        pvLoading = (ProgressView) findViewById(R.id.pv_loading);
        pvLoading.setVisibility(View.VISIBLE);

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                pvLoading.setVisibility(View.GONE);
            }
        });

        playVideo();

    }


    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        delayedHide(100);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }

    private class PlayerOnCompleteVideo implements MediaPlayer.OnCompletionListener {

        @Override
        public void onCompletion(MediaPlayer mp) {
            mVideoView.stopPlayback();
            playVideo();
        }
    }

    private void playVideo() {
        mVideoView.setVideoURI(Uri.parse(url));
        mVideoView.start();
    }

}

and My Layout file (activity_video_playing.xml) :

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".view.activity.ActivityPlayVideo4">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        >

        <VideoView android:id="@+id/videoView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:keepScreenOn="true"
            android:layout_centerInParent="true"
            />


        <com.rey.material.widget.ProgressView
            android:id="@+id/pv_loading"
            android:layout_width="48dp"
            android:layout_height="48dp"
            app:pv_autostart="true"
            app:pv_circular="true"
            app:pv_progressStyle="@style/AppProgressStyle"
            app:pv_progressMode="indeterminate"
            android:layout_gravity="center"
            android:layout_centerInParent="true"
            android:visibility="gone"
            />

    </RelativeLayout>
</FrameLayout>

Anyone can help me?!?!?

imaN NeoFighT
  • 480
  • 4
  • 13
  • you can hide the bottom navigationBar see .. https://developer.android.com/training/system-ui/immersive.html – Uttam Panchasara Jun 20 '16 at 06:54
  • i know but i want see NavigationBar and MediaController together – imaN NeoFighT Jun 20 '16 at 07:02
  • then just dont hide the navigation bar remove it code – Uttam Panchasara Jun 20 '16 at 07:03
  • dude i want see full screen , but when user clicked on screen i want see systemUi and MediaController together – imaN NeoFighT Jun 20 '16 at 07:07
  • okayy then set the delay after the 5-10 second hide the System Ui – Uttam Panchasara Jun 20 '16 at 07:09
  • it have delay for hiding, but i need too hide and show systemUi and mediaController together, – imaN NeoFighT Jun 20 '16 at 07:10
  • then hide both systemUi and mediaController on `setOnSystemUiVisibilityChangeListener` – Uttam Panchasara Jun 20 '16 at 07:15
  • Mybe it work but i think its not stable, i think the better solution is that i get the height of navigationBar and position of it ( in landscape mode in some devices navigationBar appear in bottom and in some other devices its appear in right of screen) and set margin for MediaController (margin_right or margin_bottom ) but i cant do that. – imaN NeoFighT Jun 20 '16 at 07:18
  • it will automatically resize the mediaController whenever VisibilityChanged.. try it work with me – Uttam Panchasara Jun 20 '16 at 07:21
  • i use https://developer.android.com/training/system-ui/immersive.html new way that introduced and my layout does not resize,and i think if i use previous ways that resize all content all screen and show navigationBar solve my problem, can you give me link or sample or your code? because I'm really confused, all i need to when system ui hide or show , my MediaController hide and show too, and user toggle with these two state by click on screen, and i accept it even screen resided – imaN NeoFighT Jun 20 '16 at 07:29

1 Answers1

0

I have done like this.. from here

mSystemUiHider
        .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {

            @Override
            @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
            public void onVisibilityChange(boolean visible) {

                if(visible){
                    yourMediaController.show();

                    //Also i generally add the actionbar here as well!
                    getActionBar().show();
                } else {
                    yourMediaController.hide();
                    //Also i generally add the actionbar here as well!
                    getActionBar().hide();
                }
                if (visible && AUTO_HIDE) {
                    // Schedule a hide().
                    delayedHide(AUTO_HIDE_DELAY_MILLIS);
                }
            }
        });

Hope this will help you!

For MediaController help ==> check this

Community
  • 1
  • 1
Uttam Panchasara
  • 5,735
  • 5
  • 25
  • 41