Reputation: 381
I am running an online stream, implementing the sample code:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
String httpLiveUrl = "......";
videoView.setVideoURI(Uri.parse(httpLiveUrl));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
As soon as the activity is loaded, a black screen appears and after a while the video is run. As I read in the documentation, it needs to be run on a different from the UI thread. However, when I add the run(), the video is not started at all. What is the approach here?
Upvotes: 1
Views: 43
Reputation: 17170
I don't believe this to be much of a code issue needing threads.
the activity is loaded, a black screen appears and after a while the video is run.
This observation states that the video plays, but only after properly buffering enough content to start playback.
What you can do, is to give the app user an indication that the video is being buffered by usage of showing/hiding an image of your choice in your current layout and calling VideoView#setOnPreparedListener
Here's an example of this:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
String httpLiveUrl = "......";
videoView.setVideoURI(Uri.parse(httpLiveUrl));
videoView.setMediaController(new MediaController(this));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// media file is loaded and ready to go.
hideBufferingUi();
}
});
videoView.requestFocus();
showBufferingUi();
videoView.start();
All that is left to implement here is
showBufferingUi
and hideBufferingUi
methodshths!
Upvotes: 1