https://github.com/jarvanmo/exovideoview
a simple video view for exoplayer
https://github.com/jarvanmo/exovideoview
android-mediaplayer exoplayer video
Last synced: 27 days ago
JSON representation
a simple video view for exoplayer
- Host: GitHub
- URL: https://github.com/jarvanmo/exovideoview
- Owner: JarvanMo
- License: apache-2.0
- Created: 2016-12-02T09:25:15.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T13:15:19.000Z (over 4 years ago)
- Last Synced: 2025-05-20T04:04:23.541Z (5 months ago)
- Topics: android-mediaplayer, exoplayer, video
- Language: Java
- Size: 53.6 MB
- Stars: 284
- Watchers: 12
- Forks: 71
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# ExoVideoView
ExoVideoView is based on [ExoPlayer](https://github.com/google/ExoPlayer).[中文移步至此](./README_CN.md).

### Planning new versions
**What's in ExoVideoView**
1.Process AudioFocus automatically.
2.Process its orientation by sensor automatically
3.simple gesture action supported.
4.multiple video quality supported
5.you can add custom views to the default controller.
6.multiple resize-mode supported
7.custom controller supported.
8.change the widget's visibility if you like.
## Using ExoVideoView
### 1.Dependency
The easiest way to get started using ExoVideoView is to add it as a gradle dependency. You need to make sure you have the jitpack repositories included in the build.gradle file in the root of your project:
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Next add a gradle compile dependency to the build.gradle file of your app module:
```
implementation 'com.github.JarvanMo:ExoVideoView:2.1.6'
```
### 2.In Layout
Declare ExoVideoView in your layout file as :
```xml```
### 3.In Java
ExoVideoView provides built-in ```Player``` for convenience,so we can play a video as
```java
SimpleMediaSource mediaSource = new SimpleMediaSource(url);//uri also supported
videoView.play(mediaSource);
videoView.play(mediaSource,where);//play from a particular position
```
Passing a player outside to ExoVideoView:
```java
videoView.setPlayer(player);
```
Note:never forget to release ExoPlayer:
```java
videoView.releasePlayer();
```
see details in [demo]().### 3.Orientation Management
The ExoVideoView can handle its orientation by sensor automatically only when ExoVideoVIew has a not-null OrientationListener :
```java
videoView.setOrientationListener(orientation -> {
if (orientation == SENSOR_PORTRAIT) {
//do something
} else if (orientation == SENSOR_LANDSCAPE) {
//do something
}
});
```
> NOTE:When the ExoVideoView handle its orientation automatically,The ExoVideoView will call ```activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)``` or ```activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);``` if the ```context``` in controller is an Activity.
The fullscreen management is the same as orientation management.### 4.Back Events
First,override onKeyDown:
```java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {
return videoView.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}```
Then passing a backListener to ExoVideoView:
```java
videoView.setBackListener((view, isPortrait) -> {
if (isPortrait) {
//do something
}
return false;
});
```
If return value is ```true```, operation will be interrupted.Otherwise,ExoVideoView handle its orientation by itself and ```OrientationLister.onOrientationChange()``` will be caled.
## Advance
### 1.Multi-Quality
ExoVideoView also provides a built-in multi-quality selector.The multi-quality selector
will be added to ```overlayFrameLayout``` if multi-quality is enabled and ```ExoMediaSource``` are given different qualities in current version.
```java
List qualities = new ArrayList<>();
ExoMediaSource.Quality quality =new SimpleQuality(quality,mediaSource.url());
qualities.add(quality);
mediaSource.setQualities(qualities);
```### 2.Controller Display Mode
```ExoVideoPlaybackController``` are divided into four parts:
```
1.Top
2.Top Landscape
3.Bottom
4.Bottom Landscape
```
Each of them can be hidden or shown:
```xml
app:controller_display_mode="all|none|top|top_landscape|bottom|bottom_landscape"
```
in java:
```java
videoView.setControllerDisplayMode(mode);
```
### 3.Add Custom View To Controller
Views can be added to ```ExoVideoPlaybackController``` in java.
```java
videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP, view);
videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP_LANDSCAPE, view);
videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_BOTTOM_LANDSCAPE, view);
```
### 4.Specifying A custom Layout File
Defining your own ```exo_video_playback_control_view.xml``` is useful to customize the layout of ```ExoVideoPlaybackControlView``` throughout your application. It's also possible to customize the layout for asingle instance in a layout file. This is achieved by setting the controller_layout_id attribute on a ```ExoVideoPlaybackControlView```. This will cause the specified layout to be inflated instead of ```code exo_video_playback_control_view.xml``` for only the instance on which the attribute is set.
```xml
app:controller_layout_id="@layout/my_controller"
```
### 5.Change Visibility
Sometimes,we may not like the back buttons.So let's hide it:
```java
videoView.changeWidgetVisibility(R.id.exo_player_controller_back,View.INVISIBLE);
```
For more widgets you can hide or show,see [IDS_IN_CONTROLLER](./exoplayerview/src/main/res/values/ids.xml).
> NOTE:This is a dangerous operation because I don't know what will happen to the UI.
## Others```
app:controller_background="@android:color/holo_orange_dark"
app:use_artwork="true"
app:default_artwork="@drawable/default_art"
```