Skip to content

Commit ba8b063

Browse files
authored
Track player dimensions when using the default PlayerView (or SurfaceView or TextureView) (#74)
1 parent 8348813 commit ba8b063

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

library/src/main/java/com/mux/player/MuxPlayer.kt

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
package com.mux.player
22

33
import android.content.Context
4+
import android.view.SurfaceView
5+
import android.view.TextureView
46
import androidx.media3.common.MediaItem
7+
import androidx.media3.common.Player
58
import androidx.media3.common.Player.Listener
69
import androidx.media3.datasource.DefaultDataSource
710
import androidx.media3.exoplayer.ExoPlayer
11+
import androidx.media3.exoplayer.analytics.AnalyticsListener
12+
import com.mux.player.MuxPlayer.Builder
13+
import com.mux.player.internal.Logger
814
import com.mux.player.internal.cache.MuxPlayerCache
9-
import com.mux.stats.sdk.core.model.CustomerData
10-
import com.mux.stats.sdk.muxstats.MuxStatsSdkMedia3
1115
import com.mux.player.internal.createLogcatLogger
12-
import com.mux.player.internal.Logger
1316
import com.mux.player.internal.createNoLogger
17+
import com.mux.player.media.MediaItems
1418
import com.mux.player.media.MuxDataSource
1519
import com.mux.player.media.MuxMediaSourceFactory
16-
import com.mux.player.media.MediaItems
20+
import com.mux.stats.sdk.core.model.CustomerData
1721
import com.mux.stats.sdk.muxstats.ExoPlayerBinding
1822
import com.mux.stats.sdk.muxstats.INetworkRequest
1923
import com.mux.stats.sdk.muxstats.MuxDataSdk
24+
import com.mux.stats.sdk.muxstats.MuxStatsSdkMedia3
2025
import com.mux.stats.sdk.muxstats.media3.BuildConfig as MuxDataBuildConfig
2126

2227
/**
@@ -46,7 +51,7 @@ class MuxPlayer private constructor(
4651
initialCustomerData: CustomerData,
4752
network: INetworkRequest? = null,
4853
exoPlayerBinding: ExoPlayerBinding? = null
49-
) : ExoPlayer by exoPlayer {
54+
) : Player by exoPlayer {
5055

5156
private var muxStats: MuxStatsSdkMedia3<ExoPlayer>? = null
5257
private var released: Boolean = false
@@ -55,10 +60,42 @@ class MuxPlayer private constructor(
5560
* Updates the Mux [CustomerData] reported by this player. This data will be applied until you
5661
* change it again, or [release] this player.
5762
*/
63+
@Suppress("unused")
5864
fun updateCustomerData(customerData: CustomerData) {
5965
muxStats?.updateCustomerData(customerData)
6066
}
6167

68+
@Suppress("unused")
69+
fun addAnalyticsListener(listener: AnalyticsListener) {
70+
exoPlayer.addAnalyticsListener(listener)
71+
}
72+
73+
/**
74+
* This method is optional. Mux Player automatically detects the size of the your player view
75+
*
76+
* Records the size of the player. You don't need to call this if you're using the default
77+
* `PlayerView`, or a [SurfaceView] or [TextureView].
78+
*
79+
* @param widthPx The width of the player view, in px
80+
* @param heightPx The height of the player view, in px
81+
*/
82+
@Suppress("unused")
83+
fun recordPlayerSize(widthPx: Int, heightPx: Int) {
84+
muxStats?.setPlayerSize(widthPx, heightPx)
85+
}
86+
87+
override fun setVideoSurfaceView(surfaceView: SurfaceView?) {
88+
// We don't need the whole PlayerView, the surface (inside surfaceView) is where content goes
89+
muxStats?.setPlayerView(surfaceView)
90+
exoPlayer.setVideoSurfaceView(surfaceView)
91+
}
92+
93+
override fun setVideoTextureView(textureView: TextureView?) {
94+
// We don't need the whole PlayerView, the surface (inside textureView) is where content goes
95+
muxStats?.setPlayerView(textureView)
96+
exoPlayer.setVideoTextureView(textureView)
97+
}
98+
6299
override fun release() {
63100
// good to release muxStats first, so it doesn't call to the player after release
64101
muxStats?.release()
@@ -103,7 +140,7 @@ class MuxPlayer private constructor(
103140
context = context,
104141
envKey = muxDataKey ?: "", // empty string should infer the key
105142
customerData = initialCustomerData,
106-
player = this,
143+
player = exoPlayer,
107144
playerView = null,
108145
customOptions = null,
109146
device = muxPlayerDevice,

0 commit comments

Comments
 (0)