视频播放ExoPlayer(附小demo)

视频播放ExoPlayer

GitHub

https://github.com/google/ExoPlayer

1. 介绍

ExoPlayer是一款适用于Android的应用程序级媒体播放器。它为Android的MediaPlayer API提供了一个替代方案,可以在本地和互联网上播放音频和视频。ExoPlayer支持Android的MediaPlayer API目前不支持的功能,包括DASH和SmoothStreaming自适应回放。与MediaPlayer API不同,ExoPlayer易于定制和扩展,并且可以通过Play Store应用程序更新进行更新。

2. 简单使用

相比于原生的videoview,非常重要的一点就是播放播放的资源不是直接通过videoview.setUri()方法直接实现。exoplayer有一个专门管理播放资源的东西MediaSource。

1 导入依赖

最新的依赖版本请见GitHub,演示采用2.11.7版本

//exoplayer
implementation 'com.google.android.exoplayer:exoplayer:2.11.7'
2.加入JAVA 1.8支持
compileOptions {
   
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
3 编写界面
<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/exo_playerview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="40dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@id/playercontrol"/>
4 设置播放(最简单)
    1. 设置player参数,使用SimpleExoPlayer
    1. 设置MediaSource播放资源
    1. 为playerview设置资源
// 1.设置player参数
private SimpleExoPlayer player;
 /** The scheme part of a raw resource URI. */
public static final String RAW_RESOURCE_SCHEME = "rawresource";


private void initializePlayer() {
   
        if (player==null){
   
            player = ExoPlayerFactory.newSi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值