diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a0070b..7017b77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Updated Kotlin to 1.7.0 - Updated compileSdkVersion to 33 +### Added +- New `release(Boolean releaseConvivaSdk)` function allows for registering a new `ConvivaAnalyticsIntegration` to a +reused `Player`, when called with `releaseConvivaSdk = false` on the previous instance. + ## [2.1.4] ### Fixed diff --git a/conviva/src/main/java/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegration.java b/conviva/src/main/java/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegration.java index b29bfbb..f8e64b3 100644 --- a/conviva/src/main/java/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegration.java +++ b/conviva/src/main/java/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegration.java @@ -155,8 +155,15 @@ public void updateContentMetadata(MetadataOverrides metadataOverrides) { } public void release() { + release(true); + } + + public void release(Boolean releaseConvivaSdk) { convivaVideoAnalytics.release(); - ConvivaAnalytics.release(); + detachBitmovinEventListeners(); + if (releaseConvivaSdk) { + ConvivaAnalytics.release(); + } } /** @@ -369,6 +376,42 @@ private void attachBitmovinEventListeners() { bitmovinPlayer.on(PlayerEvent.VideoPlaybackQualityChanged.class, onVideoPlaybackQualityChangedListener); } + private void detachBitmovinEventListeners() { + bitmovinPlayer.off(SourceEvent.Unloaded.class, onSourceUnloadedListener); + bitmovinPlayer.off(PlayerEvent.Error.class, onPlayerErrorListener); + bitmovinPlayer.off(SourceEvent.Error.class, onSourceErrorListener); + bitmovinPlayer.off(PlayerEvent.Warning.class, onPlayerWarningListener); + bitmovinPlayer.off(SourceEvent.Warning.class, onSourceWarningListener); + + bitmovinPlayer.off(PlayerEvent.Muted.class, onMutedListener); + bitmovinPlayer.off(PlayerEvent.Unmuted.class, onUnmutedListener); + + // Playback state events + bitmovinPlayer.off(PlayerEvent.Play.class, onPlayListener); + bitmovinPlayer.off(PlayerEvent.Playing.class, onPlayingListener); + bitmovinPlayer.off(PlayerEvent.Paused.class, onPausedListener); + bitmovinPlayer.off(PlayerEvent.StallEnded.class, onStallEndedListener); + bitmovinPlayer.off(PlayerEvent.StallStarted.class, onStallStartedListener); + bitmovinPlayer.off(PlayerEvent.PlaybackFinished.class, onPlaybackFinishedListener); + + // Seek events + bitmovinPlayer.off(PlayerEvent.Seeked.class, onSeekedListener); + bitmovinPlayer.off(PlayerEvent.Seek.class, onSeekListener); + + // Timeshift events + bitmovinPlayer.off(PlayerEvent.TimeShift.class, onTimeShiftListener); + bitmovinPlayer.off(PlayerEvent.TimeShifted.class, onTimeShiftedListener); + + // Ad events + bitmovinPlayer.off(PlayerEvent.AdStarted.class, onAdStartedListener); + bitmovinPlayer.off(PlayerEvent.AdFinished.class, onAdFinishedListener); + bitmovinPlayer.off(PlayerEvent.AdSkipped.class, onAdSkippedListener); + bitmovinPlayer.off(PlayerEvent.AdError.class, onAdErrorListener); + + bitmovinPlayer.off(PlayerEvent.VideoPlaybackQualityChanged.class, + onVideoPlaybackQualityChangedListener); + } + private synchronized void transitionState(ConvivaSdkConstants.PlayerState state) { Log.d(TAG, "Transitioning to :" + state.name()); convivaVideoAnalytics.reportPlaybackMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, state);