Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

a simple video view for exoplayer

License

NotificationsYou must be signed in to change notification settings

JarvanMo/ExoVideoView

Repository files navigation

logo

ExoVideoView

ExoVideoView is based onExoPlayer.

中文移步至此.

demo

Planning new versions

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.

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 :

<com.jarvanmo.exoplayerview.ui.ExoVideoViewandroid:id="@+id/videoView"android:layout_width="match_parent"android:layout_height="300dp"/>

3.In Java

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.

3.Orientation Management

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 callactivity.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.

4.Back Events

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.

Advance

1.Multi-Quality

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);

2.Controller Display Mode

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);

3.Add Custom View To Controller

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);

4.Specifying A custom Layout File

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"

5.Change Visibility

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.

Others

  app:controller_background="@android:color/holo_orange_dark"  app:use_artwork="true"  app:default_artwork="@drawable/default_art"

[8]ページ先頭

©2009-2025 Movatter.jp