綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 如何在android app 裡顯示IPcam的畫面

[複製連結] 查看: 3647|回覆: 2|好評: 0
跳轉到指定樓層
樓主
蝦餅 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2014-5-3 22:28
1碎鑽
本帖最後由 蝦餅 於 2014-5-3 22:34 編輯

最近在寫一個APP

要讓IPcam的畫面在自己寫的APP裡面顯示

試過了webView、imageView兩種方式


webView部份:

webView可以成功開啟IPcam的頁面

但是鏡頭畫面顯示不出來


  1. TableLayout0 = new TableLayout(this);
  2. WebView = new WebView(this);
  3. RelativeLayout0.addView(TableLayout0, relative_params(2, 2, webX, 0, webY, 0));
  4. TableLayout0.addView(WebView, 0, new RelativeLayout.LayoutParams(
  5.                 new LayoutParams(webHigh, webWide)));
  6. WebView.setWebViewClient(new WebViewClient());
  7. WebView.loadUrl("http://10.10.100.100/tw/player/mjpeg.asp");
複製代碼


後來試過發現

用平板裡原生的瀏覽器雖然可以開啟頁面

但鏡頭畫面的區塊一樣也是沒畫面

不過換成chrome之後

就可以正常顯示鏡頭畫面

Q:有辦法在android code裡面,將chrome嵌在APP裡嗎?


imageView部份:

imageView的部分則是完全無法顯示畫面

但如果改成開一般的網路圖片

就可以正常開啟


  1. ImageView26 = new ImageView(this);
  2.                
  3. try {
  4.         URL url = new URL("http://10.10.100.100/live/0/mjpeg.jpg");
  5.         URLConnection conn = url.openConnection();

  6.         HttpURLConnection httpConn = (HttpURLConnection)conn;
  7.         httpConn.setRequestMethod("GET");
  8.         httpConn.connect();

  9.         if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
  10.             InputStream inputStream = httpConn.getInputStream();

  11.             Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
  12.             inputStream.close();
  13.             ImageView26.setImageBitmap(bitmap);
  14.         }
  15. } catch (MalformedURLException e1) {
  16.         e1.printStackTrace();
  17. } catch (IOException e) {
  18.         e.printStackTrace();
  19. }
  20.                
  21. RelativeLayout0.addView(
  22.            ImageView26,
  23.            relative_params(2, 2, 25, 0, 195, 0));
複製代碼

  1. Bitmap returnBitMap(String url) {
  2.         URL myFileUrl = null;   
  3.         Bitmap bitmap = null;   
  4.         try {   
  5.          myFileUrl = new URL(url);   
  6.         } catch (MalformedURLException e) {   
  7.          e.printStackTrace();   
  8.         }   
  9.         try {   
  10.          HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();   
  11.          conn.setDoInput(true);   
  12.          conn.connect();   
  13.          InputStream is = conn.getInputStream();   
  14.          bitmap = BitmapFactory.decodeStream(is);   
  15.          is.close();   
  16.         } catch (IOException e) {   
  17.          e.printStackTrace();   
  18.         }   
  19.      return bitmap;
  20. }
複製代碼


開發工具:
平板:Samsung Galaxy Tab 2(7.0吋、3G)P3100
IPcam:mycam2

有人有遇過類似的問題嗎? 最後怎麼解決的?

「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏1 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
whl | 收聽TA | 只看該作者
發表於 2014-5-4 08:41
網路不能在 ui 下跑。
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

板凳
 樓主| 蝦餅 | 收聽TA | 只看該作者
發表於 2014-5-4 14:38
whl 發表於 2014-5-4 08:41
網路不能在 ui 下跑。

所以我應該改成這樣  對吧?


  1. WebView = new WebView(this);
  2. WebView.setWebViewClient(new WebViewClient());
  3. WebView.loadUrl("http://10.10.100.100/tw/player/mjpeg.asp");

  4. TableLayout0 = new TableLayout(this);
  5. RelativeLayout0.addView(TableLayout0, relative_params(2, 2, webX, 0, webY, 0));
  6. TableLayout0.addView(WebView, 0, new RelativeLayout.LayoutParams(
  7.                 new LayoutParams(webHigh, webWide)));
複製代碼
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則