4

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,

Adarsh V C
  • 2,314
  • 1
  • 20
  • 37

4 Answers4

5

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.

renam.antunes
  • 761
  • 1
  • 5
  • 11
  • Thanks, renam.antunes. Currently the server uses Http streaming and the retrieved video files are in .mp4 format. The other streaming enabled links like http://www.pocketjourney.com/downloads/pj/video/famous.3gp is working fine in the Android client application. Can you provide more details on server configuration required for streaming enabled server? – Adarsh V C Jun 29 '11 at 08:54
  • Here: http://stackoverflow.com/questions/1613737/server-to-stream-rtsp-to-android . Android 3.0 is supposed to work with HTTP Live Streaming and from 2.2 onward you have flash 10.1, so I guess you can write a flash based app and use RTMP/Flash HTTP Streaming. Don't know exactly how, though. – renam.antunes Jun 29 '11 at 13:04
4

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();
success_anil
  • 3,659
  • 3
  • 27
  • 31
  • Hi Anil, above code is for downloading the video and saving it in the file system and playing it. But my requirement is to play it directly from the server(Video streaming). – Adarsh V C Jun 27 '11 at 14:28
  • hi adarsh... you can directly stream a rtsp video using video view setVideoPath method. ... Then in that case it will make get request. but as far as your question is concerned you need to sent username and password in post request .. so there's one workaround if you've not already tried .. .make one http post request seprately and get the authentication token.. pass this authentication token along with the url to download video and stream it using video view – success_anil Jun 27 '11 at 14:33
2

I tried this and it worked for me :D no rtsp no nothing, just a url with a mp4 video and it played!

public class VideoActivity extends Activity {
    public static final String KEY = "video_id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fotogaleria_video);
    Intent i = getIntent();
    if(i.hasExtra(KEY)){
        String url = "https://sites.google.com/site/tempmp4download/bnm.mp4";
        VideoView vv = (VideoView)findViewById(R.id.fotogaleria_video);
        // vv.setVideoPath(url);
        vv.setVideoURI(Uri.parse(url));
        vv.setMediaController(new MediaController(this));
        vv.requestFocus();
        vv.start();

        }

    }
}
1

Look into following links

http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/

http://w3mentor.com/learn/java/android-development/android-http-services/performa-a-http-post-request-with-the-httpclient-in-android/

For streaming, I think you have to download the full file, and then show it in the video player.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Ashwani K
  • 7,880
  • 19
  • 63
  • 102
  • Thank you Ashwani. I wish to know the steps/code to get live streaming content from the response and play in the Mediaplayer or VideoView. :( – Adarsh V C Jun 21 '11 at 10:58
  • "For streaming, I think you have to download the full file, and then show it in the video player" I guess no need to download the video to stream if it is like that then how the live streaming works? – Rahul Matte Aug 04 '14 at 14:08