Skip to content

Commit

Permalink
feat(player): move to new analytics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Jul 23, 2024
1 parent 3f23979 commit cddd917
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {

// Libraries
exoPlayerVersion = '1.3.1'
analyticsVersion = '2.0.2'
analyticsVersion = '3.0.0'
}
}
plugins {
Expand Down
2 changes: 1 addition & 1 deletion player/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
24 changes: 4 additions & 20 deletions player/src/main/java/video/api/player/ApiVideoPlayerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -294,7 +293,6 @@ class ApiVideoPlayerController(
}

private val handler = Handler(looper)
private var analyticsListener: ApiVideoAnalyticsListener? = null
private val listeners = mutableListOf<Listener>()

private var firstPlay = true
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -445,6 +427,8 @@ class ApiVideoPlayerController(
}
}

private val analyticsListener = exoplayer.addApiVideoAnalyticsListener()

/**
* Gets if player is playing
*/
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit cddd917

Please sign in to comment.