2

I use following code to play video from a url. It works fine except that It first downloads video and then plays that video

  Uri uri = Uri.parse(URL);
  video.setVideoURI(uri);
  video.start();

But I want to stream the live video instead of downloading it and then play

Sourabh Saldi
  • 3,567
  • 6
  • 34
  • 57

4 Answers4

3

There are some requirements for streaming to work.

The file might not be encoded "correctly"

http://developer.android.com/guide/appendix/media-formats.html

For video content that is streamed over HTTP or RTSP, there are additional requirements:

  • For 3GPP and MPEG-4 containers, the moov atom must precede any mdat atoms, but must succeed the ftyp atom.
  • For 3GPP, MPEG-4, and WebM containers, audio and video samples corresponding to the same time offset may be no more than 500 KB apart. To minimize this audio/video drift, consider interleaving audio and video in smaller chunk sizes.

You might be on an older version of Android that doesn't support it

HTTP progressive streaming was only added in 2.2, HTTPS only supported 3.0+, Live streaming is only supported in even later versions.

Community
  • 1
  • 1
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
3

I have work on YouTube Video streaming and that was without downloading video. This will only work if you will play YouTube video .

You have to use YouTube API and using that you can easily manage your task.

You have to enable YouTube service and using Developer Key you can access YouTube API.

How to use YouTube API ? You can Find Here Sample code for same.

Out of that sample example i have use

PlayerViewDemoActivity.java & YouTubeFailureRecoveryActivity.java and that XMl view as per the needs.

Play Video

public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity
{
    String  youtube_id = "_UWXqFBF86U";

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.playerview_demo);

        YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view); // Replace your developer key
        youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored)
    {
        if (!wasRestored)
        {
            player.cueVideo(youtube_id);
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider()
    {
        return (YouTubePlayerView) findViewById(R.id.youtube_view);
    }

}

Hope this will be help you,Let me know if you have any query.

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
0

Use Like this:

Uri uri = Uri.parse(URL); //Declare your url here.

VideoView mVideoView  = (VideoView)findViewById(R.id.videoview)
mVideoView.setMediaController(new MediaController(this));       
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();

Another Method:

  String LINK = "type_here_the_link";
  VideoView mVideoView  = (VideoView) findViewById(R.id.videoview);
  MediaController mc = new MediaController(this);
  mc.setAnchorView(videoView);
  mc.setMediaPlayer(videoView);
  Uri video = Uri.parse(LINK);
  mVideoView.setMediaController(mc);
  mVideoView.setVideoURI(video);
  mVideoView.start();

If you are getting this error Couldn't open file on client side, trying server side Error in Android. and also Refer this. Hope this will give you some solution.

Community
  • 1
  • 1
Nirmal
  • 2,340
  • 21
  • 43
0

For showing buffering you have to put progressbar of ProgressDialog ,... here i post progressDialog for buffering ...

pDialog = new ProgressDialog(this);

    // Set progressbar message
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();

    try {
        // Start the MediaController
        MediaController mediacontroller = new MediaController(this);
        mediacontroller.setAnchorView(mVideoView);      

        Uri videoUri = Uri.parse(videoUrl);
        mVideoView.setMediaController(mediacontroller);
        mVideoView.setVideoURI(videoUri);

    } catch (Exception e) {

        e.printStackTrace();
    }

    mVideoView.requestFocus();
    mVideoView.setOnPreparedListener(new OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            mVideoView.start();
        }
    });
    mVideoView.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            if (pDialog.isShowing()) {
                pDialog.dismiss();
            }
            finish();               
        }
    });
Umair
  • 6,366
  • 15
  • 42
  • 50
Vaishali Sutariya
  • 5,093
  • 30
  • 32