I Want to add analytics events to exo player need following data
How this can be done
Tried following callbacks but not able to find exact solution to this
Player.EventListener
or I need to use AnalyticsListener?
Update on this found that exo player library version 2.12.0 has included PlaybackStatsListener which gives most of required analytics data but data is not accurate
playbackStatsListener.playbackStats.totalPlayTimeMs
playbackStatsListener.playbackStats.totalPausedTimeMs
these two fields are not showing accurate or reliable values.
Here is a tested piece of code on how you could use the AnalyticsListener with onIsPlayingChanged to achieve this
private var playTime = 0L // in ms
private var pauseTime = 0L // in ms
private var totalTime = 0L // in ms
private var pressedPaused = 0
private val analyticsListener: AnalyticsListener = object : AnalyticsListener {
private var initTime = 0L
override fun onIsPlayingChanged(eventTime: AnalyticsListener.EventTime, isPlaying: Boolean) {
if(isPlaying) {
if(initTime != 0L) pauseTime += System.currentTimeMillis() - initTime
initTime = System.currentTimeMillis()
} else {
if(initTime != 0L) playTime += System.currentTimeMillis() - initTime
initTime = System.currentTimeMillis()
pressedPaused++
}
totalTime = playTime+pauseTime
Log.e("onIsPlaying", "PLAYTIME: $playTime")
Log.e("onIsPlaying", "PRESSEDPAUSE: $pressedPaused")
Log.e("onIsPlaying", "PAUSETIME: $pauseTime")
Log.e("onIsPlaying", "TOTALTIME: $totalTime")
super.onIsPlayingChanged(eventTime, isPlaying)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With