Skip to content Skip to sidebar Skip to footer

How To Play Live Streaming In Android Application?

I want to make application for cricket live streaming. I want to know following things : From where I can found the links to play cricket streaming ? Which type of links are these

Solution 1:

I will try to answer your questions but there are many fundamentals you've got to learn in order to build up a successful Streaming Application.

1. From where I can found the links to play cricket streaming ?

No idea, but this is not a SO standard question anyway.

2. Which type of links are these ?

IF you mean live streaming links, there are many types but mostly they are either HLS or RTSP. HLS links are simple HTTP links that often end with a ".m3u8" postfix. (e.g "http://somewebsite.com/streams/hls_stream_video.m3u8")

RTSP links on the other hand, have a format like this: "rtsp://somewebsite.com/streams/an_rtsp_stream.mp4"

3.Is there any player to play thistypeof videos ?

Absolutely. You can do so by any means. I'm not exactly sure by "a player" whether you mean Android API player or third-party player applications. So I'll cover both cases for you and future passengers.

I) Android API: You can do so with the help of a MediaController, a MediaPlayer and a SurafceView. The latter two are also available in a unit entity known as VideoView. There is a code in the answer below, you can use that. But Be aware of two key points:

I-a) Using MediaPlayer is harder to implement but gives you more detailed control compared to VideoView.

I-b) If you use some code similar to the below answer Never call prepare() for network streams. Always prepareAsync(). And Always call setAudioStreamType() before prepareAsync. Otherwise you will face transient sync issues between Audio and Video when seeking on the progressbar.

II) Player Application: I have done streaming with MXPlayer and it works great.

There are some considerations to take before starting:

What protocol to choose?

Assuming you are targeting Android, I can advice you to narrow your choices down to HLS and RTSP. You need to study them well before making a decision. But to give you a hint. HLS is preferred when functioning on lower Bandwidths.

There are many other topics like whether to choose UDP/TCP, IP-Multicast/Broadcast and so on...

Want to delve into coding and learn Video Streaming programmatically?

Go and visit this tutorial. This is the most complete zero-to-hero guide in my opinion.


Since SO lacks a thorough post on Video Streaming, maybe I will extend my answer on demand.

Solution 2:

Follow this link :

Android Video Streaming

Below code works for me :

publicstaticvoidgetVideoFromHttp(String urlPath) {

try {
// Start the MediaControllerMediaController mediacontroller = newMediaController(mContext);
mediacontroller.setAnchorView(mVideoview);
// Get the URL from String VideoURLUri mVideo = Uri.parse(urlPath);
mVideoview.setMediaController(mediacontroller);
mVideoview.setVideoURI(mVideo);

} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();

}

mVideoview.requestFocus();
mVideoview.setOnPreparedListener(newOnPreparedListener() {
// Close the progress bar and play the videopublicvoidonPrepared(MediaPlayer mp) {
mVideoview.start();

}
});

mVideoview.setOnCompletionListener(newOnCompletionListener() {

publicvoidonCompletion(MediaPlayer mp) {

}
});

}

Solution 3:

Try this:

privatevoidplayLive(String path){

   try {
        mMediaPlayer = newMediaPlayer();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepare();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
      }
}

Post a Comment for "How To Play Live Streaming In Android Application?"