@@ -12,6 +12,7 @@ import android.os.Build
1212import android.os.SystemClock
1313import android.util.Log
1414import android.view.View
15+ import androidx.annotation.RequiresApi
1516import com.mux.android.util.convertPxToDp
1617import com.mux.android.util.oneOf
1718import com.mux.android.util.weak
@@ -25,6 +26,7 @@ import com.mux.stats.sdk.core.util.MuxLogger
2526import com.mux.stats.sdk.muxstats.MuxDataSdk.AndroidDevice
2627import kotlinx.coroutines.CoroutineScope
2728import kotlinx.coroutines.Dispatchers
29+ import org.json.JSONObject
2830import java.util.*
2931import java.util.concurrent.atomic.AtomicInteger
3032
@@ -184,6 +186,56 @@ abstract class MuxDataSdk<Player, PlayerView : View> @JvmOverloads protected con
184186 open fun orientationChange (orientation : MuxSDKViewOrientation ) =
185187 muxStats.orientationChange(orientation)
186188
189+ /* *
190+ * Call when the video is presented in a particular way, eg, fullscreen, or picture-in-picture
191+ *
192+ * You can call this method immediately after starting a view, or wait until a relevant change.
193+ * If you do the latter, the mode will be [PlaybackMode.STANDARD] until you change it.
194+ *
195+ * @param mode The playback mode being entered
196+ */
197+ open fun playbackModeChange (mode : PlaybackMode ) {
198+ muxStats.playbackModeChange(mode, null as JSONObject ? )
199+ }
200+
201+ /* *
202+ * Call when the video is presented in a particular way, eg, fullscreen, or picture-in-picture
203+ *
204+ * You can call this method immediately after starting a view, or wait until a relevant change.
205+ * If you do the latter, the mode will be [PlaybackMode.STANDARD] until you change it.
206+ *
207+ * @param mode The playback mode being entered
208+ * @param extraData Extra data to accompany this event. Will appear in the event timeline for your view
209+ */
210+ open fun playbackModeChange (mode : PlaybackMode , extraData : JSONObject ) {
211+ muxStats.playbackModeChange(mode, extraData)
212+ }
213+
214+ /* *
215+ * Call when the video is presented in a particular way, eg, fullscreen, or picture-in-picture
216+ *
217+ * You can call this method immediately after starting a view, or wait until a relevant change.
218+ * If you do the latter, the mode will be [PlaybackMode.STANDARD] until you change it.
219+ *
220+ * @param customMode The playback mode being entered
221+ */
222+ open fun playbackModeChange (customMode : String ) {
223+ muxStats.playbackModeChange(customMode, null as JSONObject ? )
224+ }
225+
226+ /* *
227+ * Call when the video is presented in a particular way, eg, fullscreen, or picture-in-picture
228+ *
229+ * You can call this method immediately after starting a view, or wait until a relevant change.
230+ * If you do the latter, the mode will be [PlaybackMode.STANDARD] until you change it.
231+ *
232+ * @param customMode The playback mode being entered
233+ * @param extraData Extra data to accompany this event. Will appear in the event timeline for your view
234+ */
235+ open fun playbackModeChange (customMode : String , extraData : JSONObject ) {
236+ muxStats.playbackModeChange(customMode, extraData)
237+ }
238+
187239 /* *
188240 * Call when the presentation of the video changes, ie Fullscreen vs Normal, etc
189241 */
@@ -459,47 +511,43 @@ abstract class MuxDataSdk<Player, PlayerView : View> @JvmOverloads protected con
459511 connectionTypeApi16()
460512 }
461513
462- @TargetApi (Build .VERSION_CODES .M )
514+ @RequiresApi (Build .VERSION_CODES .M )
463515 private fun connectionTypeApi23 (): String? {
464- contextRef?.let { context ->
516+ // use let{} so we get both a null-check and a hard ref
517+ return contextRef?.let { context ->
465518 val connectivityManager = context.getSystemService(ConnectivityManager ::class .java)
466519 val nc: NetworkCapabilities ? =
467520 connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
468521
469- return when {
522+ when {
470523 nc == null -> {
471524 MuxLogger .w(TAG , " Could not get network capabilities" )
472525 null
473526 }
474527
475- nc.hasTransport(NetworkCapabilities .TRANSPORT_ETHERNET ) -> {
528+ nc.hasTransport(NetworkCapabilities .TRANSPORT_ETHERNET ) ->
476529 CONNECTION_TYPE_WIRED
477- }
478530
479- nc.hasTransport(NetworkCapabilities .TRANSPORT_WIFI ) -> {
531+ nc.hasTransport(NetworkCapabilities .TRANSPORT_WIFI ) ->
480532 CONNECTION_TYPE_WIFI
481- }
482533
483- nc.hasTransport(NetworkCapabilities .TRANSPORT_CELLULAR ) -> {
534+ nc.hasTransport(NetworkCapabilities .TRANSPORT_CELLULAR ) ->
484535 CONNECTION_TYPE_CELLULAR
485- }
486536
487- else -> {
488- CONNECTION_TYPE_OTHER
489- }
537+ else -> CONNECTION_TYPE_OTHER
490538 }
491- } ? : return null
539+ }
492540 }
493541
494542 @Suppress(" DEPRECATION" ) // Uses deprecated APIs for backward compat
495543 private fun connectionTypeApi16 (): String? {
496- // use let{} so we get both a null-check and a hard ref for the check
497- contextRef?.let { context ->
544+ // use let{} so we get both a null-check and a hard ref
545+ return contextRef?.let { context ->
498546 val connectivityMgr = context
499547 .getSystemService(Context .CONNECTIVITY_SERVICE ) as ConnectivityManager
500548 val activeNetwork: NetworkInfo ? = connectivityMgr.activeNetworkInfo
501549
502- return if (activeNetwork == null ) {
550+ if (activeNetwork == null ) {
503551 MuxLogger .w(TAG , " Couldn't obtain network info" )
504552 null
505553 } else {
@@ -526,7 +574,7 @@ abstract class MuxDataSdk<Player, PlayerView : View> @JvmOverloads protected con
526574 }
527575 }
528576 }
529- } ? : return null // contextRef?.let {...
577+ } // contextRef?.let {...
530578 }
531579
532580 override fun getElapsedRealtime (): Long {
0 commit comments