Android-VitaMio框架使用記錄

前言

之前看了農民伯伯的文章,不得不佩服起來 這個萬能的播放器 Vitamio,默默地爲這些辛勤的開發者點個贊,
農民伯伯博客鏈接 CSDN~~Vitamio Github鏈接

自己使用經驗

第一步使用之前:在github上下載下來Vitamio的依賴包,在AS中引用過來.不會引用 自行百度吧….

第二步:自己創建一個PlayVideoOnlineActivity一個播放視頻的類,來做測試,記得Mainister註冊下和加上權限配置.

 @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Vitamio.isInitialized(this);
      setContentView(R.layout.activity_play_video);
//        m_actionBar.hide();
        playviedo();

    }

這一步就是 中 在serView 之前 初始化 ,也可以在 Vitamio.isInitialized(this); 這句話初始化,看看裏面的源代碼

 public static boolean isInitialized(Context ctx) {
    vitamioPackage = ctx.getPackageName();
    vitamioLibraryPath = ContextUtils.getDataDir(ctx) + "libs/";
    File dir = new File(getLibraryPath());
    if (dir.exists() && dir.isDirectory()) {
      String[] libs = dir.list();
      if (libs != null) {
        Arrays.sort(libs);
        for (String L : getRequiredLibs()) {
          if (Arrays.binarySearch(libs, L) < 0) {
            Log.e("Native libs %s not exists!", L);
            return false;
          }
        }
        File lock = new File(getLibraryPath() + LIBS_LOCK);
        BufferedReader buffer = null; 
        try {
          buffer = new BufferedReader(new FileReader(lock));  
          int appVersion = ContextUtils.getVersionCode(ctx);
          int libVersion = Integer.valueOf(buffer.readLine());  
          Log.i("isNativeLibsInited, APP VERSION: %d, Vitamio Library version: %d", appVersion, libVersion);
          if (libVersion == appVersion)
            return true;
        } catch (IOException e) {
          Log.e("isNativeLibsInited", e);
        } catch (NumberFormatException e) {
            Log.e("isNativeLibsInited", e);
        } finally {
          IOUtils.closeSilently(buffer);
        }
      }
    }
    return false;
  }

看了下源碼這裏是 在本地創建一個初始化lib文件夾

接下來就是給 VideoView進出初始化配置

  mVideoView = (VideoView) findViewById(R.id.surface_view);
        //   mVideoView.setVideoURI(Uri.parse(path));
        mVideoView.setVideoPath("http://movie.ks.js.cn/flv/other/2014/06/20-2.flv");//設置視頻網絡地址
        mVideoView.setMediaController(new MediaController(this));
     //視頻播放器的準備,此時播放器已經準備好了,此處可以設置一下播放速度,播放位置等等
        mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH,0);
     mVideoView.requestFocus();

這裏是初始化配置,設置網絡地址地方.不得不說 這個萬能播放器支持那麼多格式,有這麼多格式 自動解析.
還是看看源碼裏是怎麼寫的:

 public void setVideoURI(Uri uri, Map<String, String> headers) {
    mUri = uri;
    mHeaders = headers;
    mSeekWhenPrepared = 0;
    openVideo();//播放視頻
    requestLayout();
    invalidate();
  }

找啊找阿,終於找到匹配各種格式地方了

public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
    if (context == null || uri == null)
      throw new IllegalArgumentException();
    String scheme = uri.getScheme();
    if (scheme == null || scheme.equals("file")) {
      setDataSource(FileUtils.getPath(uri.toString()));
      return;
    }

    try {
      ContentResolver resolver = context.getContentResolver();
      mFD = resolver.openAssetFileDescriptor(uri, "r");
      if (mFD == null)
        return;
      setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
      return;
    } catch (Exception e) {
      closeFD();
    }
    setDataSource(uri.toString(), headers);
  }

這裏應該是設置 視頻源,
在下一層就是 調本地C的方法

 /**
   * Sets the data source (file-path or http/rtsp/mms URL) to use.
   *
   * @param path    the path of the file, or the http/rtsp/mms URL of the stream you
   *                want to play
   * @param keys   AVOption key
   * @param values AVOption value
   * @throws IllegalStateException if it is called in an invalid state
   */
private native void _setDataSource(String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, IllegalStateException;

這裏支持 http.rtsp.mms流協議傳輸,這個MeidiaPlayer就調底層so庫的方法了…JNI編程不太瞭解~

返回來看下 之前的

 mVideoView.setMediaController(new MediaController(this));

這裏就是 設置 媒體的控制器 進度條 以及時間之類的,一開始跑不起來 原來漏了這一句

其他東西 就是一些監聽器,更高級的用法還是看農民伯伯的文章後續在研究研究
有什麼說錯的地方 還望網友指教~~

發佈了32 篇原創文章 · 獲贊 5 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章