ExoPlayer尝鲜

本文是ExoPlayer的HelloWorld教程,介绍了如何将ExoPlayer添加到项目中,创建SimpleExoPlayer实例,关联到视图,准备播放器以及控制播放。通过详细步骤指导开发者开始使用ExoPlayer。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:
本文是根据ExoPlayer的HelloWorld文档翻译而来

Hello world!
Another way to get started is to work through the ExoPlayer codelab.
开始上手的另一种方式是通过ExoPlayer codelab.

For simple use cases, getting started with ExoPlayer consists of implementing the following steps:
做一些简单的使用案例,上手ExoPlayer按照下面的步骤实现

1.Add ExoPlayer as a dependency to your project.
添加ExoPlayer依赖到你的工程中
2.Create a SimpleExoPlayer instance.
创建一个SimpleExoPlayer实例对象
3.Attach the player to a view (for video output and user input).
关联播放器到视图,(视频输出,用户输入)
4.Prepare the player with a MediaSource to play.
为播放器准备一个MediaSource播放
5.Release the player when done.
结束使用时,释放播放器
These steps are described in more detail below. For a complete example, refer to PlayerActivity in the main demo app.
这些步骤在下面的描述中更加详细,一个更完整的例子在PlayerAtivity的演示版本app中

Adding ExoPlayer as a dependency
添加ExoPlayer依赖
Add repositories
添加仓库
The first step to getting started is to make sure you have the Google and JCenter repositories included in the build.gradle file in the root of your project.
开始之前的第一步要确保你有google和jcenter仓库在你的工程根目录下的build.gradle文件中引入

repositories {
    google()
    jcenter()
}

Add ExoPlayer modules
添加ExoPlayer的模块

Next add a dependency in the build.gradle file of your app module. The following will add a dependency to the full ExoPlayer library:
接下来添加一个依赖在你app模块的build.gradle文件当中。下面是一个完整的ExoPlayer哭的依赖添加

implementation ‘com.google.android.exoplayer:exoplayer:2.X.X’
where 2.X.X is your preferred version (the latest version can be found by consulting the release notes).

As an alternative to the full library, you can depend on only the library modules that you actually need. For example the following will a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值