在Android中使用Vitamio库播放视频流?

时间:2014-03-21 05:36:14

标签: android video-streaming vitamio

我正在使用图书馆Vitamio来播放rtsp直播。我尝试按如下方式运行演示视频视图类播放rtsp链接:

http://117.103.224.75:1935/live/definst/VTCHD3/VTCHD3_840x480_1200kbps.stream/playlist.m3u8

==>结果:它运行但质量非常差,加载视频非常低,视频中的图像不清晰,听不到声音。我不知道该怎么做才能让它运行平稳,画面清晰。请帮帮我这个问题!非常感谢!

这是我的代码:

private String path="http://117.103.224.75:1935/live/_definst_/VTCHD3/VTCHD3_840x480_1200kbps.stream/playlist.m3u8";

private ProgressDialog prodlg;
private VideoView mVideoView;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);
    prodlg=new ProgressDialog(this);
    prodlg.setIcon(R.drawable.ic_launcher);
    prodlg.setMessage("wating...");
    prodlg.show();

    mVideoView = (VideoView) findViewById(R.id.surface_view);

    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewDemo.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
        mVideoView.setBufferSize(2048);
        mVideoView.requestFocus();
        mVideoView.start();
        mVideoView.setMediaController(new MediaController(this));

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                prodlg.dismiss();
                mediaPlayer.setPlaybackSpeed(1.0f);
            }
        });
    }

}

我使用android平台4.0 api 14播放演示: this is my screen picture demo

1 个答案:

答案 0 :(得分:2)

如果您想使用Vitamio库来显示视频等,那么首先从这里下载Vitamio Library Free download Vitamio Library。 然后包括" ZI"和" InitActivtiy" (在Vitamio lib里面)你当前项目中的库(右键单击项目 - >包含库 - >),然后编写这行代码

 if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
        return;

在我的项目中的Oncreate Method()之后。

 @Override
protected void onCreate(Bundle savedInstanceState) 
 {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) //it will check the include library of Vitamio
        return;

之后将这行代码放在Androidmanifest.xml文件中

  <!-- (((((( Vitamio Library including in manifest file )))))) -->
   <activity android:name="io.vov.vitamio.activity.InitActivity" 
       android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden"
       android:launchMode="singleTop"
        android:theme="@android:style/Theme.NoTitleBar"
        android:windowSoftInputMode="stateAlwaysHidden"/>     

现在可以使用VideoView等显示您的视频了。