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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With