让相机模拟与 Tom G 的 HttpCamera 一起使用时出现问题

发布于 2024-10-15 00:03:05 字数 3574 浏览 4 评论 0原文

我正在尝试使用 Android 模拟器预览网络摄像头的视频。我使用了 Tom gibara 示例代码,减去了网络广播(我改为通过 http 使用 VLC 流)。

因此,我修改了SDK的“CameraPreview”应用程序以使用HttpCamera,但流从未出现。调试也没有给我任何线索。我想知道其他人是否清楚任何显而易见的事情?预览应用程序启动并保持黑色。

注意:

  1. 我已经更新了原始的 CameraPreview 类,如下所述: http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emulator.html,但引用httpCamera而不是socketcamera。
  2. 我更新了 Tom 的原始示例以引用“Camera”类型,而不是已弃用的“CameraDevice”类型。
  3. 下面是我的 CameraPreview.java。
  4. 谢谢

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:

  1. 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.
  2. I updated Tom's original example to reference "Camera" type instead of deprecated "CameraDevice" type.
  3. Below is my CameraPreview.java.
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2024-10-22 00:03:05

您尚未为 HttpCamera 指定协议。尝试
http://10.213.74.247:443

You have not specified protocol for your HttpCamera. Try
http://10.213.74.247:443

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文