Skip to content

Commit

Permalink
Releases/v1.6.1 (#105)
Browse files Browse the repository at this point in the history
## Improvements

* fix: suppress some ad events when outside of an ad break (#102)
* fix: dropped frames not tracked (#103)

### Internal Library Updates
* Update `muxstats-android` to v1.4.4
  • Loading branch information
daytime-em authored Nov 22, 2024
1 parent 612b60f commit 995a715
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 22 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ dependencies {
At_latestImplementation "androidx.media3:media3-exoplayer-hls:1.4.1"
At_latestImplementation "androidx.media3:media3-exoplayer-rtsp:1.4.1"

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

allprojects {
project.ext {
coreVersion = '1.4.2'
coreVersion = '1.4.4'
}

tasks.withType(DokkaTaskPartial.class) {
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonFinalResIds=false
4 changes: 2 additions & 2 deletions library-exo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ dependencies {
At_latestCompileOnly "androidx.media3:media3-exoplayer-hls:1.4.0"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}

afterEvaluate {
Expand Down
12 changes: 7 additions & 5 deletions library-ima/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,20 @@ dependencies {
at_1_4Api "androidx.media3:media3-exoplayer-ima:1.4.0"
//noinspection GradleDependency
at_1_4Api "androidx.media3:media3-exoplayer:1.4.0"
//noinspection GradleDependency
At_latestApi "androidx.media3:media3-exoplayer-ima:1.4.0"
//noinspection GradleDependency
At_latestApi "androidx.media3:media3-exoplayer:1.4.0"

implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.core:core-ktx:1.15.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'androidx.test.ext:junit:1.2.1'
testImplementation "io.mockk:mockk:1.12.3"
testImplementation 'org.robolectric:robolectric:4.10.3'
testImplementation 'org.robolectric:robolectric:4.11.1'

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}

afterEvaluate {
Expand Down
12 changes: 7 additions & 5 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,18 @@ dependencies {
at_1_2Api "androidx.media3:media3-common:1.2.0"
//noinspection GradleDependency
at_1_3Api "androidx.media3:media3-common:1.3.0"
//noinspection GradleDependency // benefit from optimistic matching
at_1_4Api "androidx.media3:media3-common:1.4.0"
//noinspection GradleDependency // benefit from optimistic matching
At_latestApi "androidx.media3:media3-common:1.4.0"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1"

testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'androidx.test.ext:junit:1.2.1'
testImplementation "io.mockk:mockk:1.12.3"
testImplementation 'org.robolectric:robolectric:4.10.3'
testImplementation 'org.robolectric:robolectric:4.11.1'

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ import androidx.annotation.OptIn
import androidx.media3.common.MediaLibraryInfo
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import com.mux.android.util.noneOf
import com.mux.stats.sdk.core.CustomOptions
import com.mux.stats.sdk.core.events.EventBus
import com.mux.stats.sdk.core.events.playback.AdBreakEndEvent
import com.mux.stats.sdk.core.events.playback.AdEndedEvent
import com.mux.stats.sdk.core.events.playback.AdEvent
import com.mux.stats.sdk.core.events.playback.AdFirstQuartileEvent
import com.mux.stats.sdk.core.events.playback.AdMidpointEvent
import com.mux.stats.sdk.core.events.playback.AdPauseEvent
import com.mux.stats.sdk.core.events.playback.AdPlayEvent
import com.mux.stats.sdk.core.events.playback.AdPlayingEvent
import com.mux.stats.sdk.core.events.playback.AdThirdQuartileEvent
import com.mux.stats.sdk.core.model.CustomerData
import com.mux.stats.sdk.core.model.CustomerVideoData
import com.mux.stats.sdk.core.util.MuxLogger
Expand Down Expand Up @@ -145,7 +154,24 @@ class AdCollector private constructor(
}

fun dispatch(event: AdEvent) {
eventBus.dispatch(event)

if (
muxPlayerState != MuxPlayerState.PLAYING_ADS &&
event.type.noneOf(
AdPlayingEvent.TYPE,
AdPlayEvent.TYPE,
AdFirstQuartileEvent.TYPE,
AdMidpointEvent.TYPE,
AdThirdQuartileEvent.TYPE,
AdEndedEvent.TYPE,
AdBreakEndEvent.TYPE,
AdPauseEvent.TYPE
)
) {
eventBus.dispatch(event)
} else if (muxPlayerState == MuxPlayerState.PLAYING_ADS) {
eventBus.dispatch(event)
}
}

companion object {
Expand Down
182 changes: 182 additions & 0 deletions library/src/test/java/com/mux/stats/sdk/muxstats/AdCollectorTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.mux.stats.sdk.muxstats
import com.mux.stats.media3.test.tools.AbsRobolectricTest
import com.mux.stats.sdk.core.events.EventBus
import com.mux.stats.sdk.core.events.IEvent
import com.mux.stats.sdk.core.events.playback.AdErrorEvent
import com.mux.stats.sdk.core.events.playback.AdPlayEvent
import com.mux.stats.sdk.core.events.playback.AdPlayingEvent
import com.mux.stats.sdk.core.events.playback.AdRequestEvent
import com.mux.stats.sdk.core.events.playback.AdResponseEvent
import com.mux.stats.sdk.core.events.playback.RebufferEndEvent
import io.mockk.every
import io.mockk.just
Expand Down Expand Up @@ -45,4 +50,181 @@ class AdCollectorTests : AbsRobolectricTest() {
)

}

@Test
fun testDispatchesAdPlayAndAdPlayingOnlyDuringAdBreaks() {
val dispatchedEvents = mutableListOf<IEvent>()
val eventBus = mockk<EventBus> {
every { addListener(any()) } just runs
every { removeListener(any()) } just runs
every { removeAllListeners() } just runs
every { dispatch(any()) } answers { call ->
dispatchedEvents += (call.invocation.args.first() as IEvent)
}
}
val stateCollector = MuxStateCollector(mockk<MuxStats>(relaxed = true), eventBus)
val adCollector = AdCollector.create(stateCollector, eventBus)

adCollector.dispatch(AdPlayEvent(null))
adCollector.dispatch(AdPlayingEvent(null))

Assert.assertTrue(
"adplay should not be sent to event bus",
dispatchedEvents.find { it is AdPlayEvent } == null
)

Assert.assertTrue(
"adplaying should not be sent to event bus",
dispatchedEvents.find { it is AdPlayingEvent } == null
)

dispatchedEvents.clear()
adCollector.onStartPlayingAds()

adCollector.dispatch(AdPlayEvent(null))
adCollector.dispatch(AdPlayingEvent(null))

Assert.assertTrue(
"adplay should not be sent to event bus",
dispatchedEvents.find { it is AdPlayEvent } != null
)

Assert.assertTrue(
"adplaying should not be sent to event bus",
dispatchedEvents.find { it is AdPlayingEvent } != null
)

dispatchedEvents.clear()
adCollector.onFinishPlayingAds(willPlay = true)

adCollector.dispatch(AdPlayEvent(null))
adCollector.dispatch(AdPlayingEvent(null))

Assert.assertTrue(
"adplay should not be sent to event bus",
dispatchedEvents.find { it is AdPlayEvent } == null
)

Assert.assertTrue(
"adplaying should not be sent to event bus",
dispatchedEvents.find { it is AdPlayingEvent } == null
)
}

@Test
fun testDispatchesAdErrorBothDuringAndOutsideOfAdBreaks() {
val dispatchedEvents = mutableListOf<IEvent>()
val eventBus = mockk<EventBus> {
every { addListener(any()) } just runs
every { removeListener(any()) } just runs
every { removeAllListeners() } just runs
every { dispatch(any()) } answers { call ->
dispatchedEvents += (call.invocation.args.first() as IEvent)
}
}
val stateCollector = MuxStateCollector(mockk<MuxStats>(relaxed = true), eventBus)
val adCollector = AdCollector.create(stateCollector, eventBus)

adCollector.dispatch(AdErrorEvent(null))
Assert.assertTrue(
"aderror should be sent to event bus before the start of an ad break",
dispatchedEvents.find { it is AdErrorEvent } != null
)

dispatchedEvents.clear()
adCollector.onStartPlayingAds()

adCollector.dispatch(AdErrorEvent(null))
Assert.assertTrue(
"aderror should be sent to event bus during an ad break",
dispatchedEvents.find { it is AdErrorEvent } != null
)

dispatchedEvents.clear()
adCollector.onFinishPlayingAds(willPlay = true)

adCollector.dispatch(AdErrorEvent(null))
Assert.assertTrue(
"aderror should be sent to event bus after an ad break is finished",
dispatchedEvents.find { it is AdErrorEvent } != null
)
}

@Test
fun testDispatchesAdRequestBothDuringAndOutsideOfAdBreaks() {
val dispatchedEvents = mutableListOf<IEvent>()
val eventBus = mockk<EventBus> {
every { addListener(any()) } just runs
every { removeListener(any()) } just runs
every { removeAllListeners() } just runs
every { dispatch(any()) } answers { call ->
dispatchedEvents += (call.invocation.args.first() as IEvent)
}
}
val stateCollector = MuxStateCollector(mockk<MuxStats>(relaxed = true), eventBus)
val adCollector = AdCollector.create(stateCollector, eventBus)

adCollector.dispatch(AdRequestEvent(null))
Assert.assertTrue(
"adrequest should be sent to event bus before the start of an ad break",
dispatchedEvents.find { it is AdRequestEvent } != null
)

dispatchedEvents.clear()
adCollector.onStartPlayingAds()

adCollector.dispatch(AdRequestEvent(null))
Assert.assertTrue(
"adrequest should be sent to event bus during an ad break",
dispatchedEvents.find { it is AdRequestEvent } != null
)

dispatchedEvents.clear()
adCollector.onFinishPlayingAds(willPlay = true)

adCollector.dispatch(AdRequestEvent(null))
Assert.assertTrue(
"adrequest should be sent to event bus after an ad break is finished",
dispatchedEvents.find { it is AdRequestEvent } != null
)
}

@Test
fun testDispatchesAdResponseBothDuringAndOutsideOfAdBreaks() {
val dispatchedEvents = mutableListOf<IEvent>()
val eventBus = mockk<EventBus> {
every { addListener(any()) } just runs
every { removeListener(any()) } just runs
every { removeAllListeners() } just runs
every { dispatch(any()) } answers { call ->
dispatchedEvents += (call.invocation.args.first() as IEvent)
}
}
val stateCollector = MuxStateCollector(mockk<MuxStats>(relaxed = true), eventBus)
val adCollector = AdCollector.create(stateCollector, eventBus)

adCollector.dispatch(AdResponseEvent(null))
Assert.assertTrue(
"adresponse should be sent to event bus before the start of an ad break",
dispatchedEvents.find { it is AdResponseEvent } != null
)

dispatchedEvents.clear()
adCollector.onStartPlayingAds()

adCollector.dispatch(AdResponseEvent(null))
Assert.assertTrue(
"adresponse should be sent to event bus during an ad break",
dispatchedEvents.find { it is AdResponseEvent } != null
)

dispatchedEvents.clear()
adCollector.onFinishPlayingAds(willPlay = true)

adCollector.dispatch(AdResponseEvent(null))
Assert.assertTrue(
"adresponse should be sent to event bus after an ad break is finished",
dispatchedEvents.find { it is AdResponseEvent } != null
)
}
}

0 comments on commit 995a715

Please sign in to comment.