2

The Question says it all, MediaController doesn't follow the animation applied to the view.

I've a RelativeLayout inside which I've a VideoView. MediaController is anchored to this VideoView. Now, in the activity, I bring the relative layout on the screen with some animation(say right to left). All the things inside the layout, like textview, videoview animates perfectly, but MediaController doesn't. Instead of appearing from right to left alongwith VideoView, it just appears in between the screen while the VideoView is still appearing from right to left.

Is there any way to force the animation to be applied to the MediaController.

Minimal Structure ->

RelativeLayout
|
|--- TextView
|--- VideoView + MediaController
|--- Some other view

I apply the animation on the relative Layout.

rtlAnim = AnimationUtils.loadAnimation(activity, R.anim.right_to_left);
relativeLayout.startAnimation(rtlAnim);

right_to_left.xml :

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="100%p"
        android:toXDelta="0"
        android:duration="500"/>
</set>

Any help will be appreciated.

PS : I show the mediacontroller once the videoview is prepared.

videoView.setOnPreparedListener(mediaPlayer -> mediaController.show());
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Shivam Pokhriyal
  • 1,044
  • 11
  • 26
  • get rid of the set. You dont need it for a single animation, and sets dont always work as expected – A Honey Bustard Jan 01 '20 at 20:04
  • I removed the set, though it still didn't solve the problem. @AHoneyBustard Do you think that the animation that I'm applying to the layout will be applied to the mediaController, since I just read the android docs that says mediacontroller is in a window floating above your application. So, what should be the correct way to apply the same animation to the layout as well as mediacontroller. – Shivam Pokhriyal Jan 02 '20 at 06:37

1 Answers1

1

Solved it using below code from here. Since mediaController places the controls in a floating window, so we've to manually add it to the view hierarchy. :

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    videoView.setMediaController(ctrl);
                    ctrl.show();
                    FrameLayout frameLayout = (FrameLayout) ctrl.getParent();
                    ((ViewGroup) frameLayout.getParent()).removeView(frameLayout);
                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                    params.addRule(ALIGN_BOTTOM, videoView.getId());
                    ((RelativeLayout) videoView.getParent()).addView(frameLayout, params);
                }
            });
Shivam Pokhriyal
  • 1,044
  • 11
  • 26