Bhoomika Brahmbhatt
Bhoomika Brahmbhatt

Reputation: 7415

Live mjpeg video stream from server to android

I am trying to fetch mjpeg live video stream from server to android.I read this answer.it is very helpful to me.It works with this demo url.But, In my video stream it asking for username and password.

To set url into MjpegView:

 setContentView(mv);        
 mv.setSource(MjpegInputStream.read(URL));

MjpegInputStream:

public static MjpegInputStream read(String url) {
    HttpResponse res;
    DefaultHttpClient httpclient = new DefaultHttpClient();     

   
    try {
        res = httpclient.execute(new HttpGet(URI.create(url)));
        return new MjpegInputStream(res.getEntity().getContent());              
    } catch (ClientProtocolException e) {
    } catch (IOException e) {}
    return null;
}

As in web browser whenever i open my server link..it asking for 'password' & 'username'.so where to put params in this read() ? and also want to know if my live video is in H.264 format. then how can i convert it into MJPEG format?Also its speed is very slow and not smooth.how to improve it?

Thanks in Advance!!

Upvotes: 0

Views: 2562

Answers (2)

Luciano Rodríguez
Luciano Rodríguez

Reputation: 2309

it's been a time... but to login:

DefaultHttpClient httpclient = new DefaultHttpClient();
    try {

        HttpGet httpget2 = new HttpGet(url);
        httpget2.addHeader("Authorization","Basic " + Base64.encodeToString((USERSTRING:PASSWORDSTRING).getBytes(),Base64.DEFAULT));
        res = httpclient.execute(httpget2);
        return new MjpegInputStream(res.getEntity().getContent());

    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }

Upvotes: 0

Paul van Jaarsveld
Paul van Jaarsveld

Reputation: 1564

You are promted for a login because the webcam is password protected. Normally with webcams you have to pass the username and password as part of the URL. eg. username:[email protected]:8085/folder/stream.jpg?size=large where the number at the end is the port number.

Upvotes: 1

Related Questions