How to get internal video size using EMVideoView

589 Views Asked by At

I'm using android's alternative media player through ExoMedia library (com.devbrackets.android.exomedia)

It really works great but there seem to be no way of getting the video properties, such as the width and height, which are critical for example for setting the video view size to the video's.

Is there a way to retrieve it?

2

There are 2 best solutions below

0
On BEST ANSWER

Solution is to get the video API child view and operate on that:

VideoViewApi videoViewImpl = (VideoViewApi)mButtonMediaVideo.findViewById( R.id.exomedia_video_view );
float videoWidth = videoViewImpl.getWidth();
float videoHeight = videoViewImpl.getHeight();
0
On

I found setOnVideoSizedChangedListener method in VideoView. I'm using the latest library version 4.0.3 and it's using VideoView instead of EMVideoView under com.devbrackets.android.exomedia.ui.widget package.

In setOnVideoSizedChangedListener method, I was able to get original width and height of video.

Following is the code sample about how I could get the video size.

videoView.setOnVideoSizedChangedListener(new OnVideoSizeChangedListener() {
        @Override
        public void onVideoSizeChanged(int intrinsicWidth, int intrinsicHeight) {
            Log.d("Original Video Size", "width: " + String.valueOf(intrinsicWidth) + ", " + "height: " + String.valueOf(intrinsicHeight));
            float aspectRatio = intrinsicWidth / intrinsicHeight;
            int actualHeight = (int) (videoView.getWidth() * aspectRatio);
            Log.d("VideoView Height", String.valueOf(actualHeight));
        }
    });

Please let me know if you need any further help.