Skip to content

feat: Use Media3 player API#31

Merged
hugmouse merged 39 commits intomasterfrom
feat/media3-player
Mar 11, 2026
Merged

feat: Use Media3 player API#31
hugmouse merged 39 commits intomasterfrom
feat/media3-player

Conversation

@hugmouse
Copy link
Owner

@hugmouse hugmouse commented Mar 8, 2026

Who might have known that Android has all of this API? Imagine if I read the documentation first.

hugmouse added 12 commits March 5, 2026 08:39
…L fix

- Add currentItemId to GemcapPlayerManager with @stable annotation for
  single-player semantics across multiple loaded media items
- Use Compose mutableStateOf for player and currentItemId reactivity
- Select all address bar text on focus for easier URL editing
- Fix normalizeHomeUrl to not treat dot-prefixed input as URLs
- Support downloading file-backed media by passing dataFilePath through
  the callback chain instead of falling back to empty ByteArray
- Fix size display showing "0B" for in-memory media by using actual data
  size instead of hardcoded fallback
- Only release player on collapse if collapsing the active item, so
  unrelated playback is not disrupted
- Throttle onProgress updates to every 16KB to prevent unbounded
  coroutine creation during downloads
- Consolidate downloadProgress and downloadedBytes into a single
  DownloadProgress data class
- Use Long instead of Int for progress callbacks to support large files
- Auto-play audio/video loaded to memory for consistent UX with
  file-backed media
- Reset playback error state when an item becomes active again
- Document video-pauses / audio-continues background policy
@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e34890ca-805f-492f-9047-b94fcf706ccf

📥 Commits

Reviewing files that changed from the base of the PR and between 679d6ce and b81a5b8.

📒 Files selected for processing (4)
  • app/src/main/java/mysh/dev/gemcap/ui/BrowserScreen.kt
  • app/src/main/java/mysh/dev/gemcap/ui/BrowserViewModel.kt
  • app/src/main/java/mysh/dev/gemcap/ui/content/ContentItem.kt
  • app/src/main/java/mysh/dev/gemcap/ui/content/EmbeddedMediaContent.kt

📝 Walkthrough

Walkthrough

Adds AndroidX Media3 (ExoPlayer) playback support with a ByteArray DataSource, a GemcapPlayerManager and MediaSessionService; enables file-streaming with progress in GeminiClient; extends embedded-media domain, UI and ViewModel for playback, fullscreen and temp-file handling; updates build, manifest and ProGuard.

Changes

Cohort / File(s) Summary
Build & Versions
gradle/libs.versions.toml, gradle/wrapper/gradle-wrapper.properties, app/build.gradle.kts
Add Media3 version and library entries, bump AGP and Gradle wrapper, and add Media3 dependencies to the app module.
Manifest & ProGuard
app/src/main/AndroidManifest.xml, app/proguard-rules.pro
Add FOREGROUND_SERVICE, FOREGROUND_SERVICE_MEDIA_PLAYBACK and POST_NOTIFICATIONS permissions; register .media.GemcapMediaSessionService (foregroundServiceType="mediaPlayback", exported="false"); add ProGuard keep rule for the service.
Media Core
app/src/main/java/mysh/dev/gemcap/media/ByteArrayDataSource.kt, app/src/main/java/mysh/dev/gemcap/media/GemcapPlayerManager.kt, app/src/main/java/mysh/dev/gemcap/media/GemcapMediaSessionService.kt
Introduce ByteArray-backed DataSource for Media3, GemcapPlayerManager to manage ExoPlayer + MediaSession, and a MediaSessionService scaffold — review session lifecycle, main-thread constraints and cleanup.
Networking / Streaming
app/src/main/java/mysh/dev/gemcap/network/GeminiClient.kt
Add fetchToFile() and onProgress callbacks; thread outputFile/onProgress through retry/internal fetch paths; refactor header parsing; implement file streaming with a 500 MB cap; expose internal in-memory body cap.
Domain Model
app/src/main/java/mysh/dev/gemcap/domain/GeminiModels.kt
Extend EmbeddedMedia with dataFilePath and per-item downloadProgress (new DownloadProgress) to represent temp file path and download progress.
UI — Playback & Fullscreen
app/src/main/java/mysh/dev/gemcap/ui/content/..., app/src/main/java/mysh/dev/gemcap/ui/content/FullscreenVideoDialog.kt
Replace legacy playback UI with Media3-driven components: add playback controls, progress sliders, fullscreen dialog, many composable signature changes to accept playerManager, onPlayMedia and onFullscreen.
UI Integration & ViewModel
app/src/main/java/mysh/dev/gemcap/ui/BrowserScreen.kt, app/src/main/java/mysh/dev/gemcap/ui/BrowserViewModel.kt, app/src/main/java/mysh/dev/gemcap/ui/content/ContentItem.kt
Thread playerManager through composables, expose playerManager on the ViewModel, add playEmbeddedMedia, temp-file cleanup and load-to-file vs load-to-memory flows with progress and lifecycle cleanup.
Callbacks & Feature API
app/src/main/java/mysh/dev/gemcap/ui/callbacks/BrowserCallbacksImpl.kt, app/src/main/java/mysh/dev/gemcap/ui/callbacks/FeatureCallbacks.kt
Add onPlayEmbeddedMedia and widen onDownloadEmbeddedMedia to accept nullable in-memory data and optional dataFilePath; update implementations and feature callbacks.
Downloads Utility
app/src/main/java/mysh/dev/gemcap/util/DownloadUtils.kt
Add overload to save a File to Downloads (MediaStore) by streaming from disk; existing byte-array path unchanged.
Minor UI
app/src/main/java/mysh/dev/gemcap/ui/components/controlBarComponents/AddressBar.kt
Select-all address-bar text on focus via a LaunchedEffect calling selectAll().
Resources
app/src/main/res/values/strings.xml
Add strings for loading-with-size, playback errors, unsupported format, fullscreen labels, video content description and download-unavailable messaging.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.25% 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
Title check ✅ Passed The title 'feat: Use Media3 player API' directly and clearly summarizes the main change—integration of the Media3 player API into the project, which is evidenced by extensive additions to dependencies, media playback components, and UI integration across multiple files.
Description check ✅ Passed The description 'Who might have known that Android has all of this API? Imagine if I read the documentation first.' is loosely related to the changeset as it references the Media3 API discovery, though it is casual and humorous rather than formally descriptive of the technical changes.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/media3-player

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.

@hugmouse hugmouse self-assigned this Mar 8, 2026
@coderabbitai coderabbitai bot added the enhancement New feature or request label Mar 8, 2026
coderabbitai[bot]

This comment was marked as resolved.

@hugmouse hugmouse changed the title Use Media3 player API feat: Use Media3 player API Mar 8, 2026
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@hugmouse hugmouse merged commit da5d44e into master Mar 11, 2026
2 checks passed
@hugmouse hugmouse deleted the feat/media3-player branch March 20, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant