Skip to content

Commit

Permalink
feat(*): simplify full screen management.
Browse files Browse the repository at this point in the history
`showFullScreenButton` is replaced by `fullScreenListener`
  • Loading branch information
ThibaultBee committed Oct 30, 2023
1 parent 1eddab2 commit b0fe19a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ analytics of [your viewers usage](https://api.video/product/video-analytics/).
android:id="@+id/playerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:show_fullscreen_button="true"
app:show_controls="true"
app:show_subtitles="true" />
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun ApiVideoPlayer(
factory = {
playerView.apply {
controller.setPlayerView(this)
showFullScreenButton = false
this.fullScreenListener = null
this.showControls = showControls
this.showSubtitles = showSubtitles
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MainActivity : AppCompatActivity() {
}
}

private val playerViewListener = object : ApiVideoExoPlayerView.Listener {
private val fullScreenListener = object : ApiVideoExoPlayerView.FullScreenListener {
override fun onFullScreenModeChanged(isFullScreen: Boolean) {
/**
* For fullscreen video, hides every views and forces orientation in landscape.
Expand Down Expand Up @@ -84,9 +84,11 @@ class MainActivity : AppCompatActivity() {
error.message != null -> {
error.message
}

error is ClientError -> {
error.networkResponse.statusCode.toString()
}

else -> {
error.toString()
}
Expand Down Expand Up @@ -124,7 +126,7 @@ class MainActivity : AppCompatActivity() {
}

private val playerController: ApiVideoPlayerController by lazy {
binding.playerView.listener = playerViewListener
binding.playerView.fullScreenListener = fullScreenListener
ApiVideoPlayerController(
applicationContext,
null,
Expand Down Expand Up @@ -186,10 +188,10 @@ class MainActivity : AppCompatActivity() {
binding.unmute.setOnClickListener { playerController.isMuted = false }

binding.showFullScreenButton.setOnClickListener {
binding.playerView.showFullScreenButton = true
binding.playerView.fullScreenListener = fullScreenListener
}
binding.hideFullScreenButton.setOnClickListener {
binding.playerView.showFullScreenButton = false
binding.playerView.fullScreenListener = null
}

binding.showControls.setOnClickListener { binding.playerView.showControls = true }
Expand Down
1 change: 0 additions & 1 deletion examples/view/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:show_controls="true"
app:show_fullscreen_button="true"
app:show_subtitles="true" />

<LinearLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ class ApiVideoExoPlayerView @JvmOverloads constructor(
override val playerView: PlayerView
get() = binding.playerView

var listener: Listener? = null

/**
* Shows or hides the full screen button
* Sets or gets the full screen listener.
* If set to null, the full screen button is hidden.
*/
var showFullScreenButton: Boolean = true
var fullScreenListener: FullScreenListener? = null
@SuppressLint("UnsafeOptInUsageError")
set(value) {
if (value) {
if (value != null) {
playerView.setFullscreenButtonClickListener {
listener?.onFullScreenModeChanged(it)
value.onFullScreenModeChanged(it)
}
} else {
playerView.setControllerOnFullScreenModeChangedListener(null)
Expand Down Expand Up @@ -89,16 +88,14 @@ class ApiVideoExoPlayerView @JvmOverloads constructor(
init {
val a = context.obtainStyledAttributes(attrs, R.styleable.ApiVideoExoPlayerView)
try {
showFullScreenButton =
a.getBoolean(R.styleable.ApiVideoExoPlayerView_show_fullscreen_button, true)
showControls = a.getBoolean(R.styleable.ApiVideoExoPlayerView_show_controls, true)
showSubtitles = a.getBoolean(R.styleable.ApiVideoExoPlayerView_show_subtitles, true)
} finally {
a.recycle()
}
}

interface Listener {
interface FullScreenListener {
/**
* Called when the full screen button has been clicked
*
Expand Down
1 change: 0 additions & 1 deletion player/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ApiVideoExoPlayerView">
<attr name="show_fullscreen_button" format="boolean" />
<attr name="show_controls" format="boolean" />
<attr name="show_subtitles" format="boolean" />
</declare-styleable>
Expand Down

0 comments on commit b0fe19a

Please sign in to comment.