Skip to content

task(SDK-5584) - Adds support for resuming the video on rotation and …#980

Open
Anush-Shand wants to merge 4 commits intotask/release/8.1.0from
task/SDK-5584/resume_on_rotation
Open

task(SDK-5584) - Adds support for resuming the video on rotation and …#980
Anush-Shand wants to merge 4 commits intotask/release/8.1.0from
task/SDK-5584/resume_on_rotation

Conversation

@Anush-Shand
Copy link
Copy Markdown
Contributor

@Anush-Shand Anush-Shand commented Apr 2, 2026

…foregrounding

Summary by CodeRabbit

  • New Features

    • Enhanced video player state preservation during device rotation for uninterrupted playback.
    • Improved fullscreen mode handling to maintain state and UI across orientation changes.
  • Bug Fixes

    • Optimized pause and resume behavior for seamless video playback transitions without re-buffering.

@Anush-Shand Anush-Shand requested a review from CTLalit April 2, 2026 10:30
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • \b(master|main|develop)(_\w*)?

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: be5197b0-d62b-40c7-a628-a10dd78050e8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR implements a caching system for video player handles during configuration changes. The system preserves player state and fullscreen UI across rotations by storing the player handle with associated URL and fullscreen status in a cache, then restoring it when the activity/fragment is recreated. New interface methods enable surface detachment and soft pause operations.

Changes

Cohort / File(s) Summary
Caching Infrastructure
InAppVideoPlayerCache.kt
New internal singleton that manages cached InAppVideoPlayerHandle instances with URL and fullscreen state; exposes store(), consume(), consumeFullscreen(), and release() methods for lifecycle management across configuration changes.
Interface Enhancements
InAppVideoPlayerHandle.kt
Added detachSurface() and softPause() interface methods with default no-op implementations to support surface detachment without player release and pausing without full cleanup.
Handler Integration
InAppStreamMediaHandler.kt
Refactored to cache/restore player handles and fullscreen state; distinguishes behavior between configuration changes (detach surface, cache state) and background transitions (soft pause); attempts to reuse cached players when URLs match.
Concrete Implementations
ExoplayerHandle.kt, Media3Handle.kt
Implemented softPause() to pause without releasing the player and detachSurface() to capture position, disconnect the view, and prepare for reattachment; synchronized mute UI state immediately in setMuteClickListener().

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StreamHandler as InAppStreamMediaHandler
    participant Cache as InAppVideoPlayerCache
    participant Handle as Player Handle
    participant View as PlayerView

    User->>StreamHandler: Configuration change (rotation)
    StreamHandler->>Handle: detachSurface()
    Handle->>View: Detach player & clear view
    Handle->>Handle: Capture playback position
    StreamHandler->>Cache: store(handle, url, fullscreen=true)
    Cache->>Cache: Save handle + state

    Note over StreamHandler: Activity/Fragment recreated

    StreamHandler->>StreamHandler: setup()
    StreamHandler->>Cache: consume(url)
    Cache->>Cache: Verify URL match
    Cache-->>StreamHandler: Return cached handle
    StreamHandler->>Cache: consumeFullscreen()
    Cache-->>StreamHandler: Return fullscreen state
    StreamHandler->>Handle: Reattach to new view
    StreamHandler->>View: Open fullscreen dialog
    Handle->>View: Resume playback from saved position
    User->>User: Video continues seamlessly
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly Related PRs

Suggested Reviewers

  • piyush-kukadiya
  • CTLalit
  • deeksha-rgb
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references adding support for resuming video on rotation, which aligns with the main changes in the PR (caching player state during configuration changes and restoring it). However, the title is truncated with '…' and doesn't fully convey the secondary objective of resuming on foregrounding.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/SDK-5584/resume_on_rotation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@francispereira
Copy link
Copy Markdown

francispereira commented Apr 2, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@Anush-Shand
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
clevertap-core/src/main/java/com/clevertap/android/sdk/inapp/media/InAppVideoPlayerCache.kt (1)

23-49: Consider consuming one cached entry instead of splitting handle and fullscreen state.

store() produces {handle, url, isFullscreen} together, but the restore path consumes them in two different methods and two different lifecycle phases. Returning one immutable entry from consume(url) would remove the half-consumed state and make the cache easier to reason about.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@clevertap-core/src/main/java/com/clevertap/android/sdk/inapp/media/InAppVideoPlayerCache.kt`
around lines 23 - 49, The cache currently stores handle, cachedUrl and
cachedIsFullscreen separately and exposes consume(url): InAppVideoPlayerHandle?
and consumeFullscreen(): Boolean, which allows half-consumed state; instead
create and return a single immutable cache entry (e.g., VideoCacheEntry {
handle: InAppVideoPlayerHandle, url: String, isFullscreen: Boolean }) from
consume(url) and remove consumeFullscreen; update store(handle, url,
isFullscreen) to populate the three fields as before but change consume(url) to
atomically check url, clear all cached fields (handle, cachedUrl,
cachedIsFullscreen) and return the immutable entry or null, and update callers
to use the returned entry for both handle and fullscreen state.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@clevertap-core/src/main/java/com/clevertap/android/sdk/inapp/media/InAppVideoPlayerCache.kt`:
- Around line 23-49: The cache currently stores handle, cachedUrl and
cachedIsFullscreen separately and exposes consume(url): InAppVideoPlayerHandle?
and consumeFullscreen(): Boolean, which allows half-consumed state; instead
create and return a single immutable cache entry (e.g., VideoCacheEntry {
handle: InAppVideoPlayerHandle, url: String, isFullscreen: Boolean }) from
consume(url) and remove consumeFullscreen; update store(handle, url,
isFullscreen) to populate the three fields as before but change consume(url) to
atomically check url, clear all cached fields (handle, cachedUrl,
cachedIsFullscreen) and return the immutable entry or null, and update callers
to use the returned entry for both handle and fullscreen state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77315480-d1b5-4af1-bf85-d870c17bf159

📥 Commits

Reviewing files that changed from the base of the PR and between 3b597b8 and 1e2322a.

📒 Files selected for processing (5)
  • clevertap-core/src/main/java/com/clevertap/android/sdk/inapp/media/InAppStreamMediaHandler.kt
  • clevertap-core/src/main/java/com/clevertap/android/sdk/inapp/media/InAppVideoPlayerCache.kt
  • clevertap-core/src/main/java/com/clevertap/android/sdk/video/InAppVideoPlayerHandle.kt
  • clevertap-core/src/main/java/com/clevertap/android/sdk/video/inapps/ExoplayerHandle.kt
  • clevertap-core/src/main/java/com/clevertap/android/sdk/video/inapps/Media3Handle.kt

internal object InAppVideoPlayerCache {

@Volatile private var handle: InAppVideoPlayerHandle? = null
@Volatile private var cachedUrl: String? = null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need Volatile? I assume callers of this class are from main thread and in that case , remove @volatile (which implies multi-thread awareness) and add @mainthread annotation instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

player?.pause()
}

override fun detachSurface() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Duplication between both handles

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entire ExoplayerHandle is mostly duplicate of Media3Handle. Since Exoplayer is being deprecated, we can let it be

}

override fun softPause() {
player?.pause()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Duplication between both handles

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entire ExoplayerHandle is mostly duplicate of Media3Handle. Since Exoplayer is being deprecated, we can let it be

// Sync icon with current mute state — important after rotation where a fresh
// PlayerView is created but isMuted may already be false from a prior user toggle.
val iconRes = if (isMuted) R.drawable.ct_ic_volume_off else R.drawable.ct_ic_volume_on
val descRes = if (isMuted) R.string.ct_unmute_button_content_description
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Duplication between both handles

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entire ExoplayerHandle is mostly duplicate of Media3Handle. Since Exoplayer is being deprecated, we can let it be

// Background: leave fullscreen dialog intact — it will still be there on resume.
handle?.softPause()
}
handle?.savePosition()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

savePosition() unused code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Contributor

@piyush-kukadiya piyush-kukadiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left comments

@Anush-Shand Anush-Shand requested a review from deeksha-rgb April 6, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants