I am playing live stream from this URL in android
So far, I have managed to play the video in videoView, the problem was the video stopped exactly after 23 seconds, so I have used videoview method setOnCompletionListener
(...) in order to start the video again, however, this provide bad experience for the viewer, because it stop every 23 seconds and start again, also miss several frames.
So my question is " how to make videoView buffer next part of video while playing current buffered video.
here is my code
public class TvActivity extends Activity {
// Declare variables
ProgressDialog pDialog;
VideoView videoview;
// Insert your Video URL
String VideoURL = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the layout from video_main.xml
setContentView(R.layout.videoview_main);
// Find your VideoView in your video_main.xml layout
videoview = (VideoView) findViewById(R.id.VideoView);
// Execute StreamVideo AsyncTask
VideoURL = "http://ns3622101.ip-149-202-201.eu:8000/live/fr443500/75019pa/286.ts";
// Create a progressbar
pDialog = new ProgressDialog(TvActivity.this);
// Set progressbar title
pDialog.setTitle("Video Streaming ");
// Set progressbar message
pDialog.setMessage("buffering ...");
pDialog.setIndeterminate(true);
pDialog.setCancelable(true);
// Show progressbar
pDialog.show();
try {
// Start the MediaController
final MediaController mediacontroller = new MediaController(
TvActivity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
final Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoview.start();
}
});
videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
videoview.stopPlayback();
videoview.setVideoURI(video);
videoview.requestFocus();
videoview.start();
}
});
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}
}
As you are playing video from Live Stream URL I suggest you to Stream video by using third party Player to stream video and for buffer the next part of video, I suggest you to use Android GirrafePlayer it's good Player get it from here
And as you are Streaming
.ts file
I don't think android videoview will stream this video file so try to stream this video file with .ts file streaming supported Player.
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