Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(player): move to new analytics endpoint #8

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading