-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): improve full screen usage for view based player
- Loading branch information
1 parent
2d6e0c2
commit b8524cc
Showing
11 changed files
with
231 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
player/src/main/java/video/api/player/extensions/WindowExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package video.api.player.extensions | ||
|
||
import android.view.Window | ||
import androidx.core.view.WindowCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.core.view.WindowInsetsControllerCompat | ||
|
||
/** | ||
* Hides the system UI: status bar, navigation bar and system bars. | ||
*/ | ||
fun Window.hideSystemUI() { | ||
WindowCompat.setDecorFitsSystemWindows(this, false) | ||
WindowInsetsControllerCompat(this, this.decorView).let { controller -> | ||
controller.hide(WindowInsetsCompat.Type.systemBars()) | ||
controller.hide(WindowInsetsCompat.Type.navigationBars()) | ||
controller.hide(WindowInsetsCompat.Type.statusBars()) | ||
controller.systemBarsBehavior = | ||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
player/src/main/java/video/api/player/models/ApiVideoPlayerFullScreenController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package video.api.player.models | ||
|
||
import android.util.Log | ||
import android.widget.ImageButton | ||
import androidx.fragment.app.FragmentManager | ||
import video.api.player.ApiVideoPlayerController | ||
import video.api.player.R | ||
import video.api.player.views.ApiVideoExoPlayerView | ||
import video.api.player.views.FullScreenDialogFragment | ||
|
||
/** | ||
* A class that handles the player full screen. | ||
* | ||
* Internally, it creates another player view in a full screen dialog fragment. | ||
* | ||
* @param fragmentManager The fragment manager. | ||
* @param originalPlayerView The player view. | ||
* @param playerController The player controller. | ||
* @param fullScreenListener The full screen listener if you want to lock the orientation in full screen. | ||
*/ | ||
class ApiVideoPlayerFullScreenController( | ||
private val fragmentManager: FragmentManager, | ||
private val originalPlayerView: ApiVideoExoPlayerView, | ||
private val playerController: ApiVideoPlayerController, | ||
private val fullScreenListener: ApiVideoExoPlayerView.FullScreenListener? = null | ||
) : ApiVideoExoPlayerView.FullScreenListener { | ||
/** | ||
* Full screen listener for the full screen player view. | ||
*/ | ||
private val internalFullScreenListener = object : ApiVideoExoPlayerView.FullScreenListener { | ||
override fun onFullScreenModeChanged(isFullScreen: Boolean) { | ||
if (dialogFragment.isVisible) { | ||
fullScreenPlayerView.playerView.findViewById<ImageButton>(androidx.media3.ui.R.id.exo_fullscreen) | ||
.setImageResource(R.drawable.exo_styled_controls_fullscreen_exit) | ||
playerController.switchTargetView(fullScreenPlayerView, originalPlayerView) | ||
dialogFragment.dismiss() | ||
fullScreenListener?.onFullScreenModeChanged(false) | ||
} else { | ||
Log.e(TAG, "onFullScreenModeChanged: not expected when dialog is already visible") | ||
} | ||
} | ||
} | ||
private val fullScreenPlayerView: ApiVideoExoPlayerView = originalPlayerView.duplicate().apply { | ||
this.fullScreenListener = this@ApiVideoPlayerFullScreenController.internalFullScreenListener | ||
this.playerView.findViewById<ImageButton>(androidx.media3.ui.R.id.exo_fullscreen) | ||
.setImageResource(R.drawable.exo_styled_controls_fullscreen_exit) | ||
} | ||
private val dialogFragment: FullScreenDialogFragment = | ||
FullScreenDialogFragment(fullScreenPlayerView) | ||
|
||
/** | ||
* Original view full screen listener. | ||
*/ | ||
override fun onFullScreenModeChanged(isFullScreen: Boolean) { | ||
if (!dialogFragment.isVisible) { | ||
originalPlayerView.playerView.findViewById<ImageButton>(androidx.media3.ui.R.id.exo_fullscreen) | ||
.setImageResource(R.drawable.exo_styled_controls_fullscreen_enter) | ||
playerController.switchTargetView(originalPlayerView, fullScreenPlayerView) | ||
dialogFragment.show(fragmentManager, TAG) | ||
fullScreenListener?.onFullScreenModeChanged(true) | ||
} else { | ||
Log.e(TAG, "onFullScreenModeChanged: not expected") | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TAG = "FullScreenDialogCtrl" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.