-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
580 implements custom listeners like media3 (#589)
Co-authored-by: Gaëtan Muller <[email protected]> Co-authored-by: Gaëtan Muller <[email protected]>
- Loading branch information
1 parent
794bb54
commit be67017
Showing
8 changed files
with
311 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...-player/src/main/java/ch/srgssr/pillarbox/player/analytics/PillarboxAnalyticsCollector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.player.analytics | ||
|
||
import androidx.media3.common.util.Clock | ||
import androidx.media3.common.util.ListenerSet.Event | ||
import androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime | ||
import androidx.media3.exoplayer.analytics.DefaultAnalyticsCollector | ||
import ch.srgssr.pillarbox.player.PillarboxPlayer | ||
import ch.srgssr.pillarbox.player.asset.timeRange.BlockedTimeRange | ||
import ch.srgssr.pillarbox.player.asset.timeRange.Chapter | ||
import ch.srgssr.pillarbox.player.asset.timeRange.Credit | ||
|
||
/** | ||
* Pillarbox analytics collector | ||
* | ||
* @constructor | ||
* | ||
* @param clock The [Clock] used to generate timestamps. | ||
*/ | ||
class PillarboxAnalyticsCollector( | ||
clock: Clock = Clock.DEFAULT | ||
) : DefaultAnalyticsCollector(clock), PillarboxPlayer.Listener { | ||
|
||
override fun onSmoothSeekingEnabledChanged(smoothSeekingEnabled: Boolean) { | ||
val eventTime = generateCurrentPlayerMediaPeriodEventTime() | ||
|
||
sendEventPillarbox( | ||
eventTime, PillarboxAnalyticsListener.EVENT_SMOOTH_SEEKING_ENABLED_CHANGED | ||
) { listener -> listener.onSmoothSeekingEnabledChanged(eventTime, smoothSeekingEnabled) } | ||
} | ||
|
||
override fun onTrackingEnabledChanged(trackingEnabled: Boolean) { | ||
val eventTime = generateCurrentPlayerMediaPeriodEventTime() | ||
|
||
sendEventPillarbox( | ||
eventTime, PillarboxAnalyticsListener.EVENT_TRACKING_ENABLED_CHANGED | ||
) { listener -> listener.onTrackingEnabledChanged(eventTime, trackingEnabled) } | ||
} | ||
|
||
override fun onChapterChanged(chapter: Chapter?) { | ||
val eventTime = generateCurrentPlayerMediaPeriodEventTime() | ||
|
||
sendEventPillarbox( | ||
eventTime, PillarboxAnalyticsListener.EVENT_CHAPTER_CHANGED | ||
) { listener -> listener.onChapterChanged(eventTime, chapter) } | ||
} | ||
|
||
override fun onCreditChanged(credit: Credit?) { | ||
val eventTime = generateCurrentPlayerMediaPeriodEventTime() | ||
|
||
sendEventPillarbox( | ||
eventTime, PillarboxAnalyticsListener.EVENT_CREDIT_CHANGED | ||
) { listener -> listener.onCreditChanged(eventTime, credit) } | ||
} | ||
|
||
override fun onBlockedTimeRangeReached(blockedTimeRange: BlockedTimeRange) { | ||
val eventTime = generateCurrentPlayerMediaPeriodEventTime() | ||
|
||
sendEventPillarbox( | ||
eventTime, PillarboxAnalyticsListener.EVENT_BLOCKED_TIME_RANGE_REACHED | ||
) { listener -> listener.onBlockedTimeRangeReached(eventTime, blockedTimeRange) } | ||
} | ||
|
||
private fun sendEventPillarbox(eventTime: EventTime, eventFlag: Int, event: Event<PillarboxAnalyticsListener>) { | ||
sendEvent( | ||
eventTime, eventFlag | ||
) { listener -> if (listener is PillarboxAnalyticsListener) event.invoke(listener) } | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...x-player/src/main/java/ch/srgssr/pillarbox/player/analytics/PillarboxAnalyticsListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.player.analytics | ||
|
||
import androidx.media3.exoplayer.analytics.AnalyticsListener | ||
import androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime | ||
import ch.srgssr.pillarbox.player.PillarboxPlayer | ||
import ch.srgssr.pillarbox.player.asset.timeRange.BlockedTimeRange | ||
import ch.srgssr.pillarbox.player.asset.timeRange.Chapter | ||
import ch.srgssr.pillarbox.player.asset.timeRange.Credit | ||
|
||
/** | ||
* Pillarbox analytics listener | ||
* | ||
* @see [AnalyticsListener] | ||
*/ | ||
interface PillarboxAnalyticsListener : AnalyticsListener { | ||
/** | ||
* On smooth seeking enabled changed | ||
* | ||
* @param eventTime The [EventTime]. | ||
* @param smoothSeekingEnabled The new value of [PillarboxPlayer.smoothSeekingEnabled] | ||
*/ | ||
fun onSmoothSeekingEnabledChanged(eventTime: EventTime, smoothSeekingEnabled: Boolean) {} | ||
|
||
/** | ||
* On tracking enabled changed | ||
* | ||
* @param eventTime The [EventTime]. | ||
* @param trackingEnabled The new value of [PillarboxPlayer.trackingEnabled] | ||
*/ | ||
fun onTrackingEnabledChanged(eventTime: EventTime, trackingEnabled: Boolean) {} | ||
|
||
/** | ||
* `onChapterChanged` is called when either: | ||
* - The player position changes while playing automatically. | ||
* - The use seeks to a new position. | ||
* - The playlist changes. | ||
* | ||
* @param eventTime The [EventTime]. | ||
* @param chapter `null` when the current position is not in a chapter. | ||
*/ | ||
fun onChapterChanged(eventTime: EventTime, chapter: Chapter?) {} | ||
|
||
/** | ||
* On blocked time range reached | ||
* | ||
* @param eventTime The [EventTime]. | ||
* @param blockedTimeRange The [BlockedTimeRange] reached by the player. | ||
*/ | ||
fun onBlockedTimeRangeReached(eventTime: EventTime, blockedTimeRange: BlockedTimeRange) {} | ||
|
||
/** | ||
* `onCreditChanged` is called when either: | ||
* - The player position changes while playing automatically. | ||
* - The use seeks to a new position. | ||
* - The playlist changes. | ||
* | ||
* @param eventTime The [EventTime] | ||
* @param credit `null` when the current position is not in a Credit. | ||
*/ | ||
fun onCreditChanged(eventTime: EventTime, credit: Credit?) {} | ||
|
||
companion object { | ||
/** | ||
* @see [PillarboxPlayer.EVENT_BLOCKED_TIME_RANGE_REACHED] | ||
*/ | ||
const val EVENT_BLOCKED_TIME_RANGE_REACHED = PillarboxPlayer.EVENT_BLOCKED_TIME_RANGE_REACHED | ||
|
||
/** | ||
* @see [PillarboxPlayer.EVENT_CREDIT_CHANGED] | ||
*/ | ||
const val EVENT_CREDIT_CHANGED = PillarboxPlayer.EVENT_CREDIT_CHANGED | ||
|
||
/** | ||
* @see [PillarboxPlayer.EVENT_CHAPTER_CHANGED] | ||
*/ | ||
const val EVENT_CHAPTER_CHANGED = PillarboxPlayer.EVENT_CHAPTER_CHANGED | ||
|
||
/** | ||
* @see [PillarboxPlayer.EVENT_TRACKING_ENABLED_CHANGED] | ||
*/ | ||
const val EVENT_TRACKING_ENABLED_CHANGED = PillarboxPlayer.EVENT_TRACKING_ENABLED_CHANGED | ||
|
||
/** | ||
* @see [PillarboxPlayer.EVENT_SMOOTH_SEEKING_ENABLED_CHANGED] | ||
*/ | ||
const val EVENT_SMOOTH_SEEKING_ENABLED_CHANGED = PillarboxPlayer.EVENT_SMOOTH_SEEKING_ENABLED_CHANGED | ||
} | ||
} |
Oops, something went wrong.