Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnVideoSizeChanged never called

Tags:

android

I'm working with a VideoView for showing a video stream. Because I need the MediaController to be attached to the view itself and I want to prevent the black screen flicker caused by the videoview. I've tested the below code on my Nexus 7, worked like a charm. But now I tested it on my SGS2, and for some reason OnVideoSizeChanged is never called.

@Override
public void onPrepared(MediaPlayer mp) {
    // TODO Auto-generated method stub
    Log.i("ONPREP", "called");
    mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
        @Override
        public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

            videoview.setMediaController(mc);
            mc.setAnchorView(videoview);
            videoview.setBackgroundColor(Color.TRANSPARENT);

            Log.i("ONSIZECHANGE", "called");
        }
    });
}

The video is playing like it should, I tested this by removing the OnVideoSizeChangedListener and just putting the code in the onPrepared method, but this is bringing back the screen flicker issue and leaves the mediacontroller unattached. This behaviour is also shown by the Log info in LogCat, ONPREP tag shows but never the ONSIZECHANGE. On my N7 both show, obviously cause the background color is changed.

This is the code that sets and starts the video:

videoview.setOnPreparedListener(MainActivity.this);
            mc = new MediaController(MainActivity.this);
            mc.setMediaPlayer(videoview);
            videoview.setVideoURI(videourI);
            videoview.start();

So why is it called on one device and not on another?

Edit: Tested it on my Note 2, same issue as on the SGS2.

like image 661
Raymond P Avatar asked Oct 03 '22 02:10

Raymond P


2 Answers

onVideoSizeChanged is triggered by an event from the low-level player implementation, which can be different on different platforms. It is perfectly legal for the player to call onVideoSizeChanged before onPrepared.

Actually VideoView is setting its own OnVideoSizeChangedListener callback for managing surface size, so you probably shouldn't use it at all. From your example it is not clear to me why you are using it, setMediaController should be called in onPrepared, not onVideoSizeChanged (which can be called multiple times).

like image 134
msh Avatar answered Oct 05 '22 17:10

msh


This seems to be a bug with the samsung devices. I noticed in my application that if the videoview size is 0x0 (probably also if it is invisible/gone) the onVideoSizeChange is not called. Once I set the videoview size to a non 0x0 value the onVideoSizeChange is called correctly.

like image 31
amarkovits Avatar answered Oct 05 '22 18:10

amarkovits