Question

I have a MediaController and i want it's position in top right screen,i use method SetAnchorView() follows My layout

<RelativeLayout

    android:id="@+id/content_media"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
   <VideoView

       android:id="@+id/audio_play"
       android:layout_alignParentRight="true"
       android:layout_alignParentTop="true"
       android:layout_width="fill_parent"
       android:layout_height="0dp"
       android:layout_alignParentRight="true"
            />
</RelativeLayout>

and MyMediaController

 VideoView video = (VideoView) findViewById(R.id.audio_play);
 MediaController mc = new MediaController(this);
 mc.setMediaPlayer(this);
 mc.setAnchorView(video);

But my MediaController has displayed in top center screen.Plese help me.Thanks!

No correct solution

OTHER TIPS

You can try by setting

 mc.setPadding(0, 0, 0, 0); //0's are just placeholders here

but not 0 values - try setting the values in dp to what you want in the above method. If that doesnt work as intended try setting the anchorview in the onPreparedListener once the size of the video is known.

video.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
                mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() { 
                                                @Override
                                                public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                                                        /*
                                                         *  add media controller
                                                         */

                                                        mc.setAnchorView(video);
                                                    }
                                                });
                                            }
                                        });

EDIT UPDATE: Turns out I solved a similar problem I had by extending the controller to make my own controller like this

import android.content.Context;
import android.view.View;
import android.widget.MediaController;

public class CustomController extends MediaController {
       public CustomController(Context context, View anchor)     {
          super(context);   
          super.setAnchorView(anchor);  
       }    
      @Override  
       public void setAnchorView(View view)     {  
           // Do nothing   
      } 
    } 

Now just do this in your activity - this works for me

        CustomController mc = new CustomController(this, mVideoView);
        mc.setMediaPlayer(video);
        mc.setAnchorView(video);
        video.setMediaController(mc);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top