Example usage for android.media MediaPlayer setOnVideoSizeChangedListener

List of usage examples for android.media MediaPlayer setOnVideoSizeChangedListener

Introduction

In this page you can find the example usage for android.media MediaPlayer setOnVideoSizeChangedListener.

Prototype

public void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener) 

Source Link

Document

Register a callback to be invoked when the video size is known or updated.

Usage

From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java

public void displayDialog(String vid) {
    if (getResources().getIdentifier(vid, "raw", getPackageName()) == 0) {
        /* TEST if RAW file doesn't exist then do nothing*/
    } else {//from ww  w.j  av  a 2  s .  c o  m
        final Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
        dialog.setContentView(R.layout.number_video_view);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(true);

        mVideoView = (VideoView) dialog.findViewById(R.id.videoView);
        mVideoView.setZOrderMediaOverlay(true);
        String path = "android.resource://" + getPackageName() + "/" + //R.raw.alif;
                getResources().getIdentifier(vid, "raw", getPackageName());

        FrameLayout fl = (FrameLayout) dialog.findViewById(R.id.VideoFrameLayout);
        ImageButton imageButtonClose = (ImageButton) fl.findViewById(R.id.imageButtonClose);
        imageButtonClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //dialog.dismiss();
                if (v.getId() == R.id.imageButtonClose) {
                    dialog.dismiss();
                }
            }
            // Perform button logic
        });

        // Set the media controller buttons
        if (mediaController == null) {
            mediaController = new MediaController(NumberViewActivity.this);

            // Set the videoView that acts as the anchor for the MediaController.
            mediaController.setAnchorView(mVideoView);

            // Set MediaController for VideoView
            mVideoView.setMediaController(mediaController);
        }

        mVideoView.setVideoURI(Uri.parse(path));
        mVideoView.requestFocus();

        // When the video file ready for playback.
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mediaPlayer) {
                mVideoView.seekTo(position);
                if (position == 0) {
                    mVideoView.start();
                }
                // When video Screen change size.
                mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                        // Re-Set the videoView that acts as the anchor for the MediaController
                        mediaController.setAnchorView(mVideoView);
                    }
                });
            }
        });
        dialog.show();
    }
}