From cddd9177f39bd16d5044256d32a89906c763b97c Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Tue, 23 Jul 2024 21:32:43 +0200 Subject: [PATCH] feat(player): move to new analytics endpoint --- build.gradle | 2 +- player/build.gradle | 2 +- .../api/player/ApiVideoPlayerController.kt | 24 ++++--------------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index 8f1cff9..252b0ce 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { // Libraries exoPlayerVersion = '1.3.1' - analyticsVersion = '2.0.2' + analyticsVersion = '3.0.0' } } plugins { diff --git a/player/build.gradle b/player/build.gradle index eb801e2..b18e46d 100644 --- a/player/build.gradle +++ b/player/build.gradle @@ -19,7 +19,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.13.1' api 'com.android.volley:volley:1.2.1' - implementation "video.api:android-player-analytics-exoplayer:${analyticsVersion}" + implementation "video.api.player.analytics:android-player-analytics-exoplayer:${analyticsVersion}" implementation "androidx.media3:media3-ui:${exoPlayerVersion}" implementation "androidx.media3:media3-exoplayer:${exoPlayerVersion}" implementation "androidx.media3:media3-exoplayer-hls:${exoPlayerVersion}" diff --git a/player/src/main/java/video/api/player/ApiVideoPlayerController.kt b/player/src/main/java/video/api/player/ApiVideoPlayerController.kt index 3d5b06c..fe56bea 100644 --- a/player/src/main/java/video/api/player/ApiVideoPlayerController.kt +++ b/player/src/main/java/video/api/player/ApiVideoPlayerController.kt @@ -10,7 +10,6 @@ import android.view.Surface import android.view.SurfaceView import androidx.annotation.OptIn import androidx.media3.common.C -import androidx.media3.common.MediaItem import androidx.media3.common.PlaybackException import androidx.media3.common.Player import androidx.media3.common.Player.DISCONTINUITY_REASON_SEEK @@ -26,7 +25,7 @@ import androidx.media3.exoplayer.analytics.AnalyticsListener import androidx.media3.exoplayer.source.LoadEventInfo import androidx.media3.exoplayer.source.MediaLoadData import androidx.media3.ui.PlayerView -import video.api.analytics.exoplayer.ApiVideoAnalyticsListener +import video.api.player.analytics.exoplayer.extensions.addApiVideoAnalyticsListener import video.api.player.extensions.currentVideoOptions import video.api.player.extensions.setMediaSource import video.api.player.extensions.setMp4MediaSource @@ -294,7 +293,6 @@ class ApiVideoPlayerController( } private val handler = Handler(looper) - private var analyticsListener: ApiVideoAnalyticsListener? = null private val listeners = mutableListOf() private var firstPlay = true @@ -335,22 +333,6 @@ class ApiVideoPlayerController( listeners.forEach { listener -> listener.onError(error) } } - @OptIn(UnstableApi::class) - override fun onMediaItemTransition( - eventTime: AnalyticsListener.EventTime, - mediaItem: MediaItem?, - reason: Int - ) { - // Reload analytics listener when a new video is loaded - analyticsListener?.let { exoplayer.removeAnalyticsListener(it) } - mediaItem?.localConfiguration?.uri?.toString()?.let { url -> - analyticsListener = - ApiVideoAnalyticsListener(exoplayer, url).apply { - exoplayer.addAnalyticsListener(this) - } - } - } - @OptIn(UnstableApi::class) override fun onTimelineChanged(eventTime: AnalyticsListener.EventTime, reason: Int) { if (reason == TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) { @@ -445,6 +427,8 @@ class ApiVideoPlayerController( } } + private val analyticsListener = exoplayer.addApiVideoAnalyticsListener() + /** * Gets if player is playing */ @@ -661,7 +645,7 @@ class ApiVideoPlayerController( fun release() { notificationController?.hideNotification() exoplayer.removeAnalyticsListener(exoplayerListener) - analyticsListener?.let { exoplayer.removeAnalyticsListener(it) } + exoplayer.removeAnalyticsListener(analyticsListener) notificationController?.release() exoplayer.release() }