【问题标题】:Play video stream using Vitamio library in android?在 android 中使用 Vitamio 库播放视频流?
【发布时间】:2014-03-21 05:36:13
【问题描述】:

我正在使用库 Vitamio 播放 rtsp 直播。我尝试运行演示videoview类播放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

【问题讨论】:

    标签: android video-streaming vitamio


    【解决方案1】:

    如果您想使用 Vitamio 库来显示视频等,请首先从此处Free download Vitamio Library 下载 Vitamio 库。 然后在你当前的项目中同时包含“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 等显示您的视频了。

    【讨论】:

    • "//告诉用户提供一个媒体文件的URL/路径"如何在此评论中放置文件路径。是否需要?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 2015-02-14
    相关资源
    最近更新 更多