Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Video streaming from HttpResponse object

I want to play video content from HttpResponse object. The content is downloading from a streaming sever.

My requirement is to create a HTTP POST request to the server. Request contains the URL of video, username and password of the user for authentication purpose.

I wish to know how can we create a HTTP POST request and play/download the video.

Kindly provide some hints, steps/code to proceed.

Thanks,

like image 361
Adarsh V C Avatar asked Dec 16 '22 12:12

Adarsh V C


2 Answers

I am not 100% sure, but I think that you can't stream most of the video due to the way the format stores the meta data of the video. That's why you tube has to convert your video files instead of just showing them in any format. There are protocols that encapsulate this metadata and allows you to stream any video (that's what youtube mobile does). You should take a look at RTSP: http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol

If you use an rtsp link in a videoView it should stream the video flawlessly. The point is that your problem is server and not client related.

As an exercise you could grab an rtsp link from m.youtube.com and just pass to a videoView using setVideoPath and it should work.

If can't change the server implementation then you probably them I guess your solutions are:

1) Download and decode the video yourself, you would have to handle all the metadata and ensure that the video does work though. You could, theoretically, compile ffmpeg for android to help you with that, but I couldn't compile it to android with the network option on. That is a lot of work.

2) Write your own implementation of RTSP or other streaming protocol. Download the video in a thread and them create a local server in the device to stream that video file to a videoView instance. I actually have this working on an app. Android doesn't support the specific protocol that the client's servers use and I had to get it working. It took me a full month to do this. I can't post any example code because it's all the client's, but I could give you some further info on this if you are interested.

Either way, if you can't change the server/format of the video then you should prepare for a whole lot of work.

like image 164
renam.antunes Avatar answered Dec 28 '22 09:12

renam.antunes


check the below code for showing a url http or rtsp in Video View.

Now before invoking your videoview .. just get

public class VideoViewDemo extends Activity {

    /**
     * TODO: Set the path variable to a streaming video URL or a local media
     * file path.
     */
    private String path = "";
    private VideoView mVideoView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.videoview);
        mVideoView = (VideoView) findViewById(R.id.surface_view);

        if (path == "") {
            // Tell the user to provide a media file URL/path.
            Toast.makeText(
                    VideoViewDemo.this,
                    "Please edit VideoViewDemo Activity, and set path"
                            + " variable to your media file URL/path",
                    Toast.LENGTH_LONG).show();

        } else {

            /*
             * Alternatively,for streaming media you can use
             * mVideoView.setVideoURI(Uri.parse(URLstring));
             */
            mVideoView.setVideoPath(path);
            mVideoView.setMediaController(new MediaController(this));
            mVideoView.requestFocus();

        }
    }
}

Now since your requirements are different first make http post request to your server ... get the desired input stream.. write that stream as mp4 to your local file system. then you can use below code to play content

// this can be path on file system
 String path="/adf.mp4"  ; 
    public void playVideo() { 

        MediaController mediaController = new MediaController(this);
        mediaController.setMediaPlayer(videoView);
        videoView.setVideoPath(path);   
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
        videoView.start();
        mediaController.show();
like image 34
success_anil Avatar answered Dec 28 '22 09:12

success_anil