EnhancedPlayerView is a good idea for you to improve your design and make things more easy with Media3 PlayerView
Add this line to root
build.gradle
at allprojects block code:
allprojects {
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
then add this line into your
build.gradle
app level.
dependencies {
implementation 'com.github.A0ks9:EnhancedPlayerView:1.0-Beta'
}
Add this widget to your
xml
activity file
<com.better.player.EnhancedPlayerView android:id="@+id/view_name"
android:layout_width="match_parent" android:layout_height="match_parent"
app:animation_enabled="false" app:controller_layout_id="@layout/exo_control_view"
app:auto_show="true" app:hide_by_touching="true" app:hide_during_ads="true"
app:hide_on_touch="false" app:show_timeout="0" />
important
- you should add without changing anything
app:animation_enabled="false"app:hide_on_touch="false"app:show_timeout="0"app:controller_layout_id="@layout/exo_control_view"
add ExoPlayer to your project and use it normally
After adding ExoPlayer to the project and intializing it then use it with the EnhancedPlayerView like this
binding.playerView.setPlayer(player);
player.
setMediaSource(binding.playerView.EnableCaching(mediaUrl));
player.
prepare();
Add this Code in onResume of your Activity/Fragment
binding.playerView.onResumeActivity();
Add this code in onPause of your Activity/Fragment
binding.playerView.onPauseActivity();
Add this code in onDestory of your Activity/Fragment
binding.playerView.onDestroyActivity();
if(player !=null){
binding.playerView.
setPlayer(null);
player.
release();
}
If you want to hide UserID text that moves on the screen then use this in
xml
app:show_floating_text="false"
If you want to hide Close Image then use this in
xml
app:show_close="false"
listener of Additional Button Clicks
yourPlayerView.addListener(() ->{
//clicked
});
If you want to cache the video, so it doesn't download every time the user opens the app. Then add this to the EnhancedPlayerView view
binding.playerView.initializeDatabaseProvider();
binding.playerView.
initializeActivityResult(getActivityResultRegistry());
If you are looking for video orientation based on phone orientation then Add this code in your Activity/Fragment
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
binding.playerView.onConfigurationChangedActivity(newConfig);
}
If tou are looking for PIP for the video then Add this code in your Activity/Fragment
@Override
public void onUserLeaveHint() {
binding.playerView.onUserLeaveHintActivity();
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
binding.playerView.onPictureInPictureModeChanged(isInPictureInPictureMode);
}
If you want to add new features to the library, you can change and add codes to the library. but when you add a new code then use a comment to explain the code for other developers to make the things easy to understand.