02.视频播放器简单案例.md 1.8 KB

13.视频播放器如何选择

目录介绍

  • 01.Android原生VideoView
  • 02.Google的ExoPlayer
  • 03.Vitamio视频播放框架
  • 04.B站的框架ijkplayer
  • 05.腾讯视频播放器框架

01.Android原生VideoView

02.Google的ExoPlayer

  • 根据自己的需求选择性添加依赖,如核心库和UI库,这两个可以满足基本上的视频播放需求:

    implementation 'com.google.android.exoplayer:exoplayer-core:2.X.X'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.X.X'
    
  • 整个ExoPlayer库包含5个字库,依赖5个子库和依赖整个库效果是一样的。

    exoplayer-core:核心功能 (必要)
    exoplayer-dash:支持DASH内容
    exoplayer-hls:支持HLS内容
    exoplayer-smoothstreaming:支持SmoothStreaming内容
    exoplayer-ui:用于ExoPlayer的UI组件和相关的资源。
    
  • 在布局中引用代码

    <com.google.android.exoplayer2.ui.PlayerView
       android:id="@+id/video_view"
       android:layout_width="match_parent"
       android:layout_height="match_parent"/>
    
  • 代码如何使用,超级简单

    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this,
            new DefaultTrackSelector(),new DefaultLoadControl());
    player.setPlayWhenReady(true);
    mVideoView.setPlayer(player);
    Uri uri = Uri.parse(ConstantVideo.VideoPlayerList[0]);
    DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("user-agent");
    ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(
            dataSourceFactory).createMediaSource(uri);
    // 播放
    player.prepare(mediaSource);
    

03.Vitamio视频播放框架

04.B站的框架ijkplayer

05.腾讯视频播放器框架