Exoplayer2学习--新建ExoPlayer

首先是引入exoplayer2库
...
implementation 'com.google.android.exoplayer:exoplayer-core:2.6.0'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.6.0'
...

目前官方库中自带了两种Exoplayer实现, 分别是SimpleExoPlayer和ExoPlayerImpl.

实际上在SimpleExoPlayer内部, 其播放功能是委托给ExoPlayerImpl实现的.

private final ExoPlayer player;
// Build the player and associated objects.
player = createExoPlayerImpl(renderers, trackSelector, loadControl);
....
protected ExoPlayer createExoPlayerImpl(Renderer[] renderers, TrackSelector trackSelector,
  LoadControl loadControl) {
    return new ExoPlayerImpl(renderers, trackSelector, loadControl);
}

问题: SimpleExoPlayer与ExoPlayerImpl有什么区别? 在功能上有什么不同 ? 实际使用时应该怎么选择?
-- 如果没有特殊需求, SimpleExoPlayer就能满足基本功能了, 不需要自定义

ExoPlayer的创建是通过工厂类ExoPlayerFactory来实现的. 里面重载了各种参数的创建方法, 下面是最简单的一个:

/**
* Creates a {@link SimpleExoPlayer} instance.
*
* @param context A {@link Context}.
* @param trackSelector The {@link TrackSelector} that will be used by the instance.
*/
public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector     trackSelector) {
  return newSimpleInstance(new DefaultRenderersFactory(context), trackSelector);
}


 /**
  * Creates an {@link ExoPlayer} instance.
  *
  * @param renderers The {@link Renderer}s that will be used by the instance.
  * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 */
 public static ExoPlayer newInstance(Renderer[] renderers, TrackSelector trackSelector) {
   return newInstance(renderers, trackSelector, new DefaultLoadControl());
 }

代码

你可能感兴趣的:(Exoplayer2学习--新建ExoPlayer)