开发者

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,


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.


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();


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();

        }

    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜