- Notifications
You must be signed in to change notification settings - Fork71
a simple video view for exoplayer
License
JarvanMo/ExoVideoView
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ExoVideoView is based onExoPlayer.
What's in ExoVideoView
1.Process AudioFocus automatically.2.Process its orientation by sensor automatically3.simple gesture action supported.4.multiple video quality supported5.you can add custom views to the default controller.6.multiple resize-mode supported7.custom controller supported.8.change the widget's visibility if you like.
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'
Declare ExoVideoView in your layout file as :
<com.jarvanmo.exoplayerview.ui.ExoVideoViewandroid:id="@+id/videoView"android:layout_width="match_parent"android:layout_height="300dp"/>
ExoVideoView provides built-inPlayer
for convenience,so we can play a video as
SimpleMediaSourcemediaSource =newSimpleMediaSource(url);//uri also supportedvideoView.play(mediaSource);videoView.play(mediaSource,where);//play from a particular position
Passing a player outside to ExoVideoView:
videoView.setPlayer(player);
Note:never forget to release ExoPlayer:
videoView.releasePlayer();
see details indemo.
The ExoVideoView can handle its orientation by sensor automatically only when ExoVideoVIew has a not-null OrientationListener :
videoView.setOrientationListener(orientation -> {if (orientation ==SENSOR_PORTRAIT) {//do something }elseif (orientation ==SENSOR_LANDSCAPE) {//do something } });
NOTE:When the ExoVideoView handle its orientation automatically,The ExoVideoView will call
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
oractivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
if thecontext
in controller is an Activity.The fullscreen management is the same as orientation management.
First,override onKeyDown:
@OverridepublicbooleanonKeyDown(intkeyCode,KeyEventevent) {if (keyCode ==KeyEvent.KEYCODE_BACK) {returnvideoView.onKeyDown(keyCode,event); }returnsuper.onKeyDown(keyCode,event); }
Then passing a backListener to ExoVideoView:
videoView.setBackListener((view,isPortrait) -> {if (isPortrait) {//do something }returnfalse; });
If return value istrue
, operation will be interrupted.Otherwise,ExoVideoView handle its orientation by itself andOrientationLister.onOrientationChange()
will be caled.
ExoVideoView also provides a built-in multi-quality selector.The multi-quality selectorwill be added tooverlayFrameLayout
if multi-quality is enabled andExoMediaSource
are given different qualities in current version.
List<ExoMediaSource.Quality>qualities =newArrayList<>();ExoMediaSource.Qualityquality =newSimpleQuality(quality,mediaSource.url());qualities.add(quality);mediaSource.setQualities(qualities);
ExoVideoPlaybackController
are divided into four parts:
1.Top2.Top Landscape3.Bottom4.Bottom Landscape
Each of them can be hidden or shown:
app:controller_display_mode="all|none|top|top_landscape|bottom|bottom_landscape"
in java:
videoView.setControllerDisplayMode(mode);
Views can be added toExoVideoPlaybackController
in java.
videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP,view);videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP_LANDSCAPE,view);videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_BOTTOM_LANDSCAPE,view);
Defining your ownexo_video_playback_control_view.xml
is useful to customize the layout ofExoVideoPlaybackControlView
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 aExoVideoPlaybackControlView
. This will cause the specified layout to be inflated instead ofcode exo_video_playback_control_view.xml
for only the instance on which the attribute is set.
app:controller_layout_id="@layout/my_controller"
Sometimes,we may not like the back buttons.So let's hide it:
videoView.changeWidgetVisibility(R.id.exo_player_controller_back,View.INVISIBLE);
For more widgets you can hide or show,seeIDS_IN_CONTROLLER.
NOTE:This is a dangerous operation because I don't know what will happen to the UI.
app:controller_background="@android:color/holo_orange_dark" app:use_artwork="true" app:default_artwork="@drawable/default_art"
About
a simple video view for exoplayer