让相机模拟与 Tom G 的 HttpCamera 一起使用时出现问题
我正在尝试使用 Android 模拟器预览网络摄像头的视频。我使用了 Tom gibara 示例代码,减去了网络广播(我改为通过 http 使用 VLC 流)。
因此,我修改了SDK的“CameraPreview”应用程序以使用HttpCamera,但流从未出现。调试也没有给我任何线索。我想知道其他人是否清楚任何显而易见的事情?预览应用程序启动并保持黑色。
注意:
- 我已经更新了原始的 CameraPreview 类,如下所述: http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emulator.html,但引用httpCamera而不是socketcamera。
- 我更新了 Tom 的原始示例以引用“Camera”类型,而不是已弃用的“CameraDevice”类型。
- 下面是我的 CameraPreview.java。
- 谢谢
您
package com.example.android.apis.graphics;
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import java.io.IOException;
import android.graphics.Canvas;
// ----------------------------------------------------------------------
public class CameraPreview extends Activity {
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
setContentView(mPreview);
}
}
// ----------------------------------------------------------------------
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
//Camera mCamera;
HttpCamera mCamera;//changed
Preview(Context context) {
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
//mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);//changed
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
//mCamera = Camera.open();
this.StartCameraPreview(holder);
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
//mCamera.stopPreview();//changed
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
//Camera.Parameters parameters = mCamera.getParameters();
//parameters.setPreviewSize(w, h);
//mCamera.setParameters(parameters);
//mCamera.startPreview();
this.StartCameraPreview(holder);
}
private void StartCameraPreview(SurfaceHolder sh)
{
mCamera = new HttpCamera("10.213.74.247:443", 640, 480, true);//changed
try {
//mCamera.setPreviewDisplay(holder);
Canvas c = sh.lockCanvas(null);
mCamera.capture(c);
sh.unlockCanvasAndPost(c);
} catch (Exception exception) {
//mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}
}
I am trying to use the android emulator to preview video from webcam. I have used the tom gibara sample code, minus the webbroadcaster (i am instead using VLC streaming via http).
So, I have modified the SDK's "CameraPreview" app to use the HttpCamera, but the stream never appears. Debugging through doesn't give me any clues either. I wonder if anything obvious is clear to others? The preview app launches and remains black.
Notes:
- I have updated the original CameraPreview class as described here: http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emulator.html, but referencing httpCamera instead of socketcamera.
- I updated Tom's original example to reference "Camera" type instead of deprecated "CameraDevice" type.
- Below is my CameraPreview.java.
- THANK YOU
package com.example.android.apis.graphics;
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import java.io.IOException;
import android.graphics.Canvas;
// ----------------------------------------------------------------------
public class CameraPreview extends Activity {
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
setContentView(mPreview);
}
}
// ----------------------------------------------------------------------
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
//Camera mCamera;
HttpCamera mCamera;//changed
Preview(Context context) {
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
//mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);//changed
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
//mCamera = Camera.open();
this.StartCameraPreview(holder);
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
//mCamera.stopPreview();//changed
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
//Camera.Parameters parameters = mCamera.getParameters();
//parameters.setPreviewSize(w, h);
//mCamera.setParameters(parameters);
//mCamera.startPreview();
this.StartCameraPreview(holder);
}
private void StartCameraPreview(SurfaceHolder sh)
{
mCamera = new HttpCamera("10.213.74.247:443", 640, 480, true);//changed
try {
//mCamera.setPreviewDisplay(holder);
Canvas c = sh.lockCanvas(null);
mCamera.capture(c);
sh.unlockCanvasAndPost(c);
} catch (Exception exception) {
//mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未为 HttpCamera 指定协议。尝试
http://10.213.74.247:443
You have not specified protocol for your HttpCamera. Try
http://10.213.74.247:443