tags:

views:

24

answers:

2

Hi, I am writing an Android App where I am playing video using VideoView,but the mediaController appears only after tapping the screen.Is this correct procedure ? If not how can we make it to appear without tapping on the screen.

Thanks in Advance,

+1  A: 

You can display it with the show() method but not from the OnCreate method of your activity containing your VideoView because the VideoView is not yet attached to a SurfaceHolder (or something like that). You will have use a similar procedure:

public class ActivityPreHomeVideo extends Activity implements SurfaceHolder.Callback{

    private VideoView mVideoView;
    private MediaController mMediaController;

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

        setContentView(R.layout.videolayout);
        mVideoView = (VideoView) findViewById(R.id.videolayout_video);

        mMediaController = new MediaController(this);
        mMediaController.setMediaPlayer(mVideoView);
        mMediaController.setAnchorView(mVideoView);
        mVideoView.setMediaController(mMediaController);

        //Set a callback when the VideoView is displayed
        mVideoView.getHolder().addCallback(this);

        mVideoView.setVideoPath("http://.../your_video.mp4");
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // Display the mediaController for 3 seconds
        mMediaController.show();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
    }
}

Hope it will help.

ol_v_er