使用Vitamio库流式传输m3u8

时间:2016-02-13 19:03:06

标签: android video-streaming android-videoview vitamio

我正在使用Vitamio library来播放m3u8,但它不起作用 logcat:avformat_open_input: Invalid data found when processing input : -1094995529

enter image description here

这是我尝试过的:

  

VideoStream:

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import io.vov.vitamio.LibsChecker;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.MediaPlayer.OnBufferingUpdateListener;
import io.vov.vitamio.MediaPlayer.OnInfoListener;
import io.vov.vitamio.widget.VideoView;


public class VideoStream extends Activity implements OnInfoListener, OnBufferingUpdateListener {
    private static final String TAG = "VideoStream";
    private String path;

    private VideoView mVideoView;
    private ProgressBar pb;
    private TextView downloadRateView, loadRateView;
    private Uri uri;



    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        if (!LibsChecker.checkVitamioLibs(this))
            return;
        setContentView(R.layout.video_stream);

        path = "http://video4.earthcam.com/fecnetwork/fridays_5th.flv/playlist.m3u8";

        mVideoView = (VideoView) findViewById(R.id.buffer);
        pb = (ProgressBar) findViewById(R.id.probar);

        downloadRateView = (TextView) findViewById(R.id.download_rate);
        loadRateView = (TextView) findViewById(R.id.load_rate);
        uri = Uri.parse(path);
        mVideoView.setVideoURI(uri);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
        mVideoView.setOnInfoListener(this);
        mVideoView.setOnBufferingUpdateListener(this);
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                mediaPlayer.setPlaybackSpeed(1.0f);
            }
        });
    }
    @Override
    public boolean onInfo(MediaPlayer mp, int what, int extra) {
        switch (what) {
            case MediaPlayer.MEDIA_INFO_BUFFERING_START:
                if (mVideoView.isPlaying()) {
                    mVideoView.pause();
                    pb.setVisibility(View.VISIBLE);
                    downloadRateView.setText("");
                    loadRateView.setText("");
                    downloadRateView.setVisibility(View.VISIBLE);
                    loadRateView.setVisibility(View.VISIBLE);

                }
                break;
            case MediaPlayer.MEDIA_INFO_BUFFERING_END:
                mVideoView.start();
                pb.setVisibility(View.GONE);
                downloadRateView.setVisibility(View.GONE);
                loadRateView.setVisibility(View.GONE);
                break;
            case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED:
                downloadRateView.setText("" + extra + "kb/s" + "  ");
                break;
        }
        return true;
    }

    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        loadRateView.setText(percent + "%");
    }
}
  

video_stream.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <io.vov.vitamio.widget.CenterLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <io.vov.vitamio.widget.VideoView
            android:id="@+id/buffer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />
    </io.vov.vitamio.widget.CenterLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="horizontal" >

        <ProgressBar
            android:id="@+id/probar"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/download_rate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="" />

        <TextView
            android:id="@+id/load_rate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="" />
    </LinearLayout>

</RelativeLayout>
  

清单:

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name">
      <activity android:name=".VideoStream"
                android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="landscape">
             <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" />

问题似乎与Vitamio有关。我怎样才能解决这次崩溃?
非常感谢你。

2 个答案:

答案 0 :(得分:1)

2天后,我找到了解决办法:) 所以我要说的第一件事就是我很困惑!

您可能需要像我一样使用Vitamio。现在的情况是,如果将库包含为本地库项目(File-New-Import模块),它应该可以正常工作,但是如果通过添加依赖项来包含它({ {1}})在build.gradle中,出现上述问题。

答案 1 :(得分:0)

当您使用https://url replce http://url时,因为它仅支持 MMS RTSP(RTP,SDP),RTMP HTTP限制协议和库在项目中添加为模块。