Android 台灣中文網
標題:
如何在android app 裡顯示IPcam的畫面
[打印本頁]
作者:
蝦餅
時間:
2014-5-3 22:28
標題:
如何在android app 裡顯示IPcam的畫面
本帖最後由 蝦餅 於 2014-5-3 22:34 編輯
最近在寫一個APP
要讓IPcam的畫面在自己寫的APP裡面顯示
試過了webView、imageView兩種方式
webView部份:
webView可以成功開啟IPcam的頁面
但是鏡頭畫面顯示不出來
TableLayout0 = new TableLayout(this);
WebView = new WebView(this);
RelativeLayout0.addView(TableLayout0, relative_params(2, 2, webX, 0, webY, 0));
TableLayout0.addView(WebView, 0, new RelativeLayout.LayoutParams(
new LayoutParams(webHigh, webWide)));
WebView.setWebViewClient(new WebViewClient());
WebView.loadUrl("http://10.10.100.100/tw/player/mjpeg.asp");
複製代碼
後來試過發現
用平板裡原生的瀏覽器雖然可以開啟頁面
但鏡頭畫面的區塊一樣也是沒畫面
不過換成chrome之後
就可以正常顯示鏡頭畫面
Q:有辦法在android code裡面,將chrome嵌在APP裡嗎?
imageView部份:
imageView的部分則是完全無法顯示畫面
但如果改成開一般的
網路圖片
就可以正常開啟
ImageView26 = new ImageView(this);
try {
URL url = new URL("http://10.10.100.100/live/0/mjpeg.jpg");
URLConnection conn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream inputStream = httpConn.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
inputStream.close();
ImageView26.setImageBitmap(bitmap);
}
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
RelativeLayout0.addView(
ImageView26,
relative_params(2, 2, 25, 0, 195, 0));
複製代碼
Bitmap returnBitMap(String url) {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
複製代碼
開發工具:
平板:Samsung Galaxy Tab 2(7.0吋、3G)P3100
IPcam:mycam2
有人有遇過類似的問題嗎? 最後怎麼解決的?
作者:
whl
時間:
2014-5-4 08:41
網路不能在 ui 下跑。
作者:
蝦餅
時間:
2014-5-4 14:38
whl 發表於 2014-5-4 08:41
網路不能在 ui 下跑。
所以我應該改成這樣 對吧?
WebView = new WebView(this);
WebView.setWebViewClient(new WebViewClient());
WebView.loadUrl("http://10.10.100.100/tw/player/mjpeg.asp");
TableLayout0 = new TableLayout(this);
RelativeLayout0.addView(TableLayout0, relative_params(2, 2, webX, 0, webY, 0));
TableLayout0.addView(WebView, 0, new RelativeLayout.LayoutParams(
new LayoutParams(webHigh, webWide)));
複製代碼
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1