# ExoPlayer **Repository Path**: ts_ohos/ExoPlayer ## Basic Information - **Project Name**: ExoPlayer - **Description**: An extensible media player for Ohos. - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: release-v2 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-11-08 - **Last Updated**: 2022-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #ExoPlayer 本项目是基于开源项目ExoPlayer进行harmonyos化的移植和开发的,可以通过项目标签以及 [github地址](https://github.com/google/ExoPlayer) 移植版本:源release-v2 (f1b37bc) 版本 ## 项目介绍 ### 项目名称:ExoPlayer ### 所属系列:harmonyos的第三方组件适配移植 ### 功能:An extensible media player for harmonyos。 ### 项目移植状态:部分移植 ### 未实现功能: 1. drm相关不支持(harmonyos暂不支持) 2. 广告相关不支持(源库依赖其他三方组件,harmonyos不支持) ### 调用差异:基本没有使用差异,请参照demo使用 ### 原项目Doc地址:https://github.com/google/ExoPlayer ### 编程语言:java ### 项目截图(涉及文件仅供demo测试使用) ![demo运行效果](art/entry.png) ![运行效果](art/entry.gif) ## 安装教程 #### 方案一 可以先下载项目,将项目中的library库提取出来放在所需项目中通过build配置 ```Java dependencies { implementation project(path: ':library:common') implementation project(path: ':library:ui') implementation project(path: ':library:core') ... } ``` #### 方案二 - 1.项目根目录的build.gradle中的repositories添加: ```groovy buildscript { repositories { ... mavenCentral() } ... } allprojects { repositories { ..... maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } jcenter() } } ``` - 2.开发者在自己的项目中添加依赖 ```groovy dependencies { dependencies { // On demand import implementation 'com.gitee.ts_ohos:exoplayer-core:2.0.7' implementation 'com.gitee.ts_ohos:exoplayer-common:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-decoder:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-extractor:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-database:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-hls:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-smoothstreaming:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-transformer:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-dash:2.0.6' implementation 'com.gitee.ts_ohos:exoplayer-ui:2.0.5' implementation 'com.gitee.ts_ohos:exoplayer-datasource:2.0.5' } } ``` ## How to use ### 用法一: // 添加播放器布局 ```java ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build(); player.setRepeatMode(Player.REPEAT_MODE_OFF); player.setMediaSource(mediaSource); player.prepare(); player.play(); ``` ### 用法二: ```java ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build(); // Build the media items. MediaItem firstItem = MediaItem.fromUri(firstVideoUri); MediaItem secondItem = MediaItem.fromUri(secondVideoUri); // Add the media items to be played. player.addMediaItem(firstItem); player.addMediaItem(secondItem); // Prepare the player. player.prepare(); // Start the playback. player.play(); ``` ### 用法三: // 添加播放器布局 ```java // 找布局 playerView = findViewById(R.id.player_view); // Instantiate the player. player = new ExoPlayer.Builder(context).build(); // Attach player to the view. playerView.setPlayer(player); // Set the media item to be played. player.setMediaItem(mediaItem); // Prepare the player. player.prepare(); ```