黑屏,同时试图在android系统流网络摄像机 [英] Black screen while trying to stream IP camera in android

查看:225
本文介绍了黑屏,同时试图在android系统流网络摄像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的深化发展Android应用程序来监控一些IP摄像机。
我使用的<一个href=\"http://$c$c.google.com/p/android-camera-axis/source/browse/trunk/serealisation/src/de/mjpegsample/MjpegView/?r=33\"相对=nofollow> MjpegView类的流视频。

I’m developping an android app to monitor some IP cameras. I’m using the MjpegView Class to stream the video.

我有三个摄像头。

    - 摄像机1:公共相机,我互联网上找到,无需用户名/密码
    - Camera 1: A public camera i found on internet, without user/password.
    - 相机2:公共摄像头,但这个需要用户名/密码
    - Camera 2: A public camera but this one require username/password.
    - 相机3:摄像机我要在我的应用程序最后使用。它也将要求提供信用凭证。
    - Camera 3: The camera I’m going to use finally in my app. It will also ask for credentials.

在我的主要活动的code是以下内容:

The code in my main activity is the following:

public class MainActivity extends Activity {
    private MjpegView mv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Camera 1
        String URL = "http://216.62.222.101/mjpg/video.mjpg";

        //Camera 2
        // String URL = "http://user:user@iprobocam.marmitek.com/cgi/mjpg/mjpg.cgi";

        //Camera 3
        // String URL = "http://MyIp:MyPort/mjpg/video.mjpg";

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mv = new MjpegView(this);
        setContentView(mv);
        mv.setSource(MjpegInputStream.read(URL));
        mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
        mv.showFps(true);
    }

    public void onPause() {
        super.onPause();
        mv.stopPlayback();
}

我可以流相机1没有问题。当我运行的摄像机2或3的应用程序没有错误既不警告,但我得到的最多的是一个黑色的屏幕。我这吼声与鉴别一个问题,但如果我从我的相机中取出它,我得到相同的结果,黑屏。

I can stream the camera 1 without problems. When I run the app with the cameras 2 or 3 there are no errors neither warnings but the most I get is a black screen. I thougth it was a problem with the authentification but if I remove it from my camera I get the same result, the black screen.

是什么,使他们中的一些工作,但相机的区别不是别人?

What is the difference between the cameras that makes some of them work but not others?

感谢您事先的任何帮助。

Thanks in advance for any help.

---编辑---

我发现一些奇怪而带有照相机2上运行的应用程序。
我赶上 MjpegView 类的异常时,它会调用该方法 MjpegInputStream.readMjpegFrame
更深层次看我注意到,该方法 getEndOfSeqeunce 总是返回1,而摄像机1返回值较高(66和68之间)。(效果很好的一种)

I've found something weird while running the app with the camera 2. I catch an exception in MjpegView class when it calls the method MjpegInputStream.readMjpegFrame. Looking deeper I notice that the method getEndOfSeqeunce always return 1 while Camera 1 (the one which works well) return higher values (between 66 and 68).

我希望这能给人这里发生了什么的想法......

I hope this can give someone an idea of what is happening here...

推荐答案

最后我解决了!

我不知道为什么它没有工作的我第一次尝试以流这个相机中取出认证。但是今天我又试了一次,现在它的作品。

I don't know why it didn't work the first time I tried to stream this camera removing the Authentication. But today I've tried again and now it works.

所以,现在的问题是在验证。这是不可能在浏览器中添加凭据的URL等。

So now the problem was in the Authentication. It's not possible to add the credentials in the URL like in a browser.

我只是修改了 MjpegInputStream 来设置凭据在了HTTPClient

I just modified the MjpegInputStream to set the credentials in the HTTPClient:

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(new AuthScope(host, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password));
res = httpclient.execute(new HttpGet(URI.create(url)));

是的,最后它的工作

And yes, finally it's working

这篇关于黑屏,同时试图在android系统流网络摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆