Stream Android video from an HttpResponse object

I want to play video content from an HttpResponse object. Content is downloaded from the streaming server.

My requirement is to create an HTTP POST request for the server. The request contains the video URL, username and password for authentication purposes.

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

Please provide some hints, steps / code to continue.

Thanks,

+4
source share
4 answers

I am not 100% sure, but I think that you cannot transfer most of the video because of the way the format stores the video metadata. That is why you should convert your video files and not display them in any format. There are protocols that encapsulate this metadata and allow you to stream any video (which is what the YouTube mobile phone does). You should take a look at RTSP: http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol

If you use the rtsp link in a video, it should seamlessly transmit the video. The fact is that your problem is with the server, not with the client.

As an exercise, you can grab the rtsp link from m.youtube.com and just go to the video video using setVideoPath and it should work.

If you cannot change the server implementation, you probably believe that your solutions are:

1) Download and decode the video yourself, you have to process all the metadata and ensure that the video really works. Theoretically, you could compile ffmpeg for android to help you with this, but I could not compile it for Android with the network option. This is a lot of work.

2) Write your own implementation of RTSP or another streaming protocol. Download the video in the stream and create a local server on the device to transfer this video file to the videoView instance. I'm actually working on an application. Android does not support the specific protocol that client servers use, and I had to make it work. It took me a whole month to do this. I cannot post any sample code because it is all client-side, but I could give you more information about this if you are interested.

In any case, if you cannot change the server / video format, you should prepare for a lot of work.

+5
source

check the code below to display the url urls or rtsp in video view mode.

Now before calling your video review .. 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 that your requirements are different, first make an HTTP request to your server ... get the desired input stream .. write this 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(); 
+4
source

I tried this and it worked for me: D no rtsp there was nothing, just the url with the 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(); } } } 
+2
source

All Articles