2013-07-22 98 views
0

我正試圖從服務器獲取mjpeg直播視頻流到android.I閱讀this answer.it對我非常有幫助。它可以與this一起演示url.But,在我的視頻流中它要求輸入用戶名和密碼。從服務器直播到Android的mjpeg視頻流

要設置網址到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; 
} 

如網頁瀏覽器,每當我打開我的服務器link..it要求 '密碼' &「username'.so 哪裏把參數放在這個read()中?也想知道我的現場視頻是否在H.264 格式。那麼我怎樣才能將它轉換成MJPEG格式?它的速度非常慢,而且不平滑。如何改善它?

在此先感謝!

回答

1

由於攝像頭受密碼保護,因此您被要求進行登錄。通常使用網絡攝像頭時,您必須將用戶名和密碼作爲URL的一部分。例如。用戶名:[email protected]:8085/folder/stream.jpg?size = large其中最後的數字是端口號。

0

這是一段時間......但登錄:

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