Skip to content

Commit e286e0d

Browse files
added logic to handle edge cases to match iOS behavior
1 parent 552add0 commit e286e0d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

media/src/main/java/com/mparticle/media/MediaSession.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class MediaSession protected constructor(builder: Builder) {
119119
var storedPlaybackTime: Double = 0.0 //On Pause calculate playback time and clear currentPlaybackTime
120120
private set
121121
private var sessionSummarySent = false // Ensures we only send summary event once
122+
private var pausedByAdBreak: Boolean = false // Tracks if content was paused by an ad break (for resume logic)
122123

123124
private var testing = false // Enabled for test cases
124125

@@ -579,15 +580,21 @@ class MediaSession protected constructor(builder: Builder) {
579580
currentPlaybackStartTimestamp?.let {
580581
storedPlaybackTime += ((System.currentTimeMillis() - it) / 1000)
581582
currentPlaybackStartTimestamp = null
583+
pausedByAdBreak = true
584+
} ?: run {
585+
// Content was already paused, don't mark as paused by ad break
586+
pausedByAdBreak = false
582587
}
583588
}
584589
}
585590

586591
private fun resumeContentTimeIfAdBreakExclusionEnabled() {
587592
if (excludeAdBreaksFromContentTime) {
588-
if (currentPlaybackStartTimestamp != null) {
593+
// Only resume if content was paused by the ad break, not if it was already paused
594+
if (pausedByAdBreak && currentPlaybackStartTimestamp == null) {
589595
currentPlaybackStartTimestamp = System.currentTimeMillis()
590596
}
597+
pausedByAdBreak = false
591598
}
592599
}
593600

0 commit comments

Comments
 (0)