Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Jun 24, 2024
1 parent bcba06c commit 1234e66
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package ch.srgssr.pillarbox.player.analytics
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.common.Timeline
import androidx.media3.common.Timeline.Window
import androidx.media3.exoplayer.analytics.AnalyticsListener
import androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime
import androidx.media3.exoplayer.source.LoadEventInfo
Expand Down Expand Up @@ -75,6 +76,7 @@ class PlaybackSessionManager : AnalyticsListener {
}

private val sessions = HashMap<String, Session>()
private val window = Window()

/**
* Listener
Expand Down Expand Up @@ -105,7 +107,7 @@ class PlaybackSessionManager : AnalyticsListener {
* @return A [Session] associated with `mediaItem`.
*/
fun getOrCreateSession(mediaItem: MediaItem): Session {
val session = sessions.firstNotNullOfOrNull { if (it.value.mediaItem.isTheSame(mediaItem)) it.value else null }
val session = sessions.values.firstOrNull { it.mediaItem.isTheSame(mediaItem) }
if (session == null) {
val newSession = Session(mediaItem)
sessions[newSession.sessionId] = newSession
Expand All @@ -128,7 +130,7 @@ class PlaybackSessionManager : AnalyticsListener {
val newItemIndex = newPosition.mediaItemIndex
DebugLogger.debug(TAG, "onPositionDiscontinuity reason = ${StringUtil.discontinuityReasonString(reason)}")
if (oldItemIndex != newItemIndex && !eventTime.timeline.isEmpty) {
val newSession = getOrCreateSession(eventTime.timeline.getWindow(newItemIndex, Timeline.Window()).mediaItem)
val newSession = getOrCreateSession(eventTime.timeline.getWindow(newItemIndex, window).mediaItem)
currentSession = newSession
}
}
Expand All @@ -148,7 +150,6 @@ class PlaybackSessionManager : AnalyticsListener {
return
}
val timeline = eventTime.timeline
val window = Timeline.Window()
val listNewItems = ArrayList<MediaItem>()
for (i in 0 until timeline.windowCount) {
val mediaItem = timeline.getWindow(i, window).mediaItem
Expand All @@ -168,7 +169,6 @@ class PlaybackSessionManager : AnalyticsListener {
}

override fun onLoadStarted(eventTime: EventTime, loadEventInfo: LoadEventInfo, mediaLoadData: MediaLoadData) {
// Log.d(TAG, "onLoadStarted ${eventTime.getMediaItem().mediaMetadata.title}")
if (eventTime.timeline.isEmpty) return
val mediaItem = eventTime.getMediaItem()
if (mediaItem != MediaItem.EMPTY) {
Expand Down

0 comments on commit 1234e66

Please sign in to comment.