无法使用Vitamio从IP摄像机打开流

时间:2018-02-08 08:19:49

标签: android rtsp vitamio

我正在使用Vitamio 5.0.2而我正试图从IP摄像头打开一个流。它适用于VLC播放器,但不适用于我的应用程序。

我会发布我的设置,希望有人可以尝试帮助我,或者如果我做错了就给我一个提示......

这是来自Vitamio的Android Manifest,我添加了所有必要的权限,我找到了寻找答案:

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="io.vov.vitamio"
      android:versionCode="400"
      android:versionName="5.2">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application>
    <activity
            android:name="io.vov.vitamio.activity.InitActivity"
            android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.NoTitleBar"
            android:windowSoftInputMode="stateAlwaysHidden"/>
</application>

这是我的活动布局,其中我试图打开流:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:gravity="center"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <io.vov.vitamio.widget.VideoView
        android:id="@+id/videoView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <ProgressBar
        android:id="@+id/progressBarCam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone" />

</FrameLayout>

这是活动中的设置:

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

    Vitamio.isInitialized(getApplicationContext());

    setContentView(R.layout.test_camera_activity);
    videoView = (VideoView) findViewById(R.id.videoView);
    progressBar = (ProgressBar) findViewById(R.id.progressBarCam);
    videoView.setOnPreparedListener(this);
    videoView.setOnErrorListener(this);
    videoView.setOnInfoListener(this);
}


 private void initPlayer() {

    try {
        switch (streamingType) {
            case HIGH_STREAM:
                mediaURL = camera.getHiQualityStream();
                break;
            case LOW_STREAM:
                mediaURL = camera.getLowQualityStream();
                break;
            default:
                exitError();
                break;
        }
    } catch (Exception e) {
        Log.d("STREAM_URL", "Failed to get media url");
    }

    if (mediaURL == null) {
        exitError();
        return;
    }

    videoView.setBufferSize(2048);

    HashMap<String, String> options = new HashMap<>();
    options.put("rtsp_transport", "tcp");
    options.put("headers", "User-Agent: myUserAgent\r\n");
    videoView.setVideoURI(Uri.parse(mediaURL), options);

    videoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
    videoView.getHolder().setFormat(PixelFormat.RGBX_8888);
    videoView.setVideoChroma(MediaPlayer.VIDEOCHROMA_RGB565);
    videoView.start();
    videoView.requestFocus();
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(new MediaController(this));

    mediaController.setOnSnapShotListner(new MediaController.OnSnapShotListner() {
        @Override
        public void snapShot() {
            if (camera != null) {
                takeSnapshot();
            }
        }
    });

    mediaController.setOnExitListner(new MediaController.OnExitListner() {
        @Override
        public void onExit() {
            finish();
        }
    });

    if (camera.getName() == null) {
        mediaController.setFileName("");
    } else {
        mediaController.setFileName(camera.getName());
    }
}

我试过调试它,但我找不到它失败的原因。在MediaPlayer.java类中,在handleMessage方法中,收到的第一条消息是MEDIA_ERROR,从未调用MEDIA_PREPARED和MEDIA_INFO ......有什么想法吗?

0 个答案:

没有答案