Skip to content

Add Cast support for short-form content#190

Open
amanc3765 wants to merge 5 commits intoandroid:mainfrom
amanc3765:feature/cast-local-media
Open

Add Cast support for short-form content#190
amanc3765 wants to merge 5 commits intoandroid:mainfrom
amanc3765:feature/cast-local-media

Conversation

@amanc3765
Copy link

This PR introduces Cast support to the Socialite Timeline, allowing users to cast short-form videos directly to Cast-enabled devices.

Key Changes:

  • Dependencies: Bumped AndroidX Media3 to 1.9.0 to enable the latest CastPlayer features.
  • Timeline Cast Support: Added CastPlayer into the Timeline to seamlessly hand over playback between local and remote Cast device.
  • Local Media Proxy: Google Cast receivers apps cannot natively read Android file paths. This PR implements a dynamic, secure HTTP server (LocalMediaServer) that safely proxies local media (content:// and file://) to the remote Cast device.

@gemini-code-assist
Copy link

Summary of Changes

Hello @amanc3765, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Socialite application by integrating Google Cast functionality into the video timeline. Users can now cast short-form video content from their device to compatible Cast receivers, providing a more versatile viewing experience. The implementation includes upgrading the Media3 library, introducing a local HTTP server to handle secure streaming of local media to Cast devices, and updating the UI to include a Cast button.

Highlights

  • Cast Integration: Implemented Google Cast support for short-form video content within the Socialite Timeline, enabling seamless playback transfer to Cast-enabled devices.
  • Media3 Upgrade: Updated AndroidX Media3 library to version "1.9.0" to leverage the latest CastPlayer features and improvements.
  • Local Media Proxy Server: Introduced a LocalMediaServer (based on NanoHTTPD) to securely proxy local media files (content:// and file:// URIs) over HTTP, making them accessible to remote Cast receivers.
  • Dynamic Player Switching: The TimelineViewModel now dynamically switches between local ExoPlayer and CastPlayer based on the Cast device connection status, ensuring continuous playback.
  • UI Enhancements: Added a MediaRouteButton to the video player UI in the Timeline, allowing users to easily initiate and manage Cast sessions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .idea/markdown.xml
    • Added a new configuration file for Markdown settings, specifically enabling the "Compose (experimental)" preview panel provider.
  • app/build.gradle.kts
    • Increased the minSdk version from "21" to "23".
    • Added new dependencies: "androidx.media3:media3-cast" for Cast functionality and "org.nanohttpd:nanohttpd" for the local media server.
  • app/src/main/AndroidManifest.xml
    • Added meta-data for "com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" to specify "DefaultCastOptionsProvider".
    • Registered "androidx.mediarouter.media.MediaTransferReceiver" to handle media transfer events.
  • app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/Timeline.kt
    • Modified the Timeline composable to accept and pass down an "isRemote" boolean state, indicating whether playback is currently on a remote Cast device.
  • app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/TimelineViewModel.kt
    • Imported necessary classes for Cast and local media server.
    • Injected LocalMediaServer into the ViewModel.
    • Introduced castPlayer and isRemote mutable states to manage Cast playback.
    • Implemented init and onCleared blocks to start and stop the LocalMediaServer lifecycle.
    • Added a castPlayerListener to handle DeviceInfo changes, enabling seamless transfer of media playback between local and remote players.
    • Created getMediaItemForUri to convert local URIs (content://, file://) into HTTP URLs served by LocalMediaServer when casting.
    • Updated the player variable to be of type Player? and assigned the castPlayer to it.
    • Modified releasePlayer to also release the castPlayer.
    • Adjusted changePlayerItem to use getMediaItemForUri and conditionally use the preload manager based on isRemote status.
  • app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/TimelineVerticalPager.kt
    • Updated TimelineVerticalPager and TimelinePage composables to accept the isRemote parameter.
    • Used androidx.compose.runtime.key(isRemote) to ensure PlayerSurface recomposition when switching between local and remote playback.
    • Extracted the info button and added a MediaRouteButton into a new PlayerControls composable, which is now displayed over the PlayerSurface.
  • app/src/main/java/com/google/android/samples/socialite/ui/videoedit/VideoEditScreenViewModel.kt
    • Modified EditedMediaItemSequence creation to explicitly specify TRACK_TYPE_VIDEO and TRACK_TYPE_AUDIO for the builder.
  • app/src/main/java/com/google/android/samples/socialite/utils/LocalMediaServer.kt
    • Added a new utility class LocalMediaServer which extends NanoHTTPD.
    • This server proxies local content:// or file:// URIs over HTTP, making them accessible to Cast receivers.
    • Includes logic to prevent unauthorized access by verifying currentSharedUri.
    • Provides a method getLocalIpAddress() to determine the device's local IP.
  • gradle/libs.versions.toml
    • Updated the media3 library version reference from "1.8.0" to "1.9.0".
    • Added new library definitions for "media3-cast" and "nanohttpd".
Activity
  • The pull request has been created by amanc3765. No further human activity (comments, reviews, or progress updates) has been recorded yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds Google Cast support to the timeline, a significant feature enhancement. The implementation correctly uses CastPlayer to manage playback sessions and introduces a LocalMediaServer to proxy local files, which is a necessary and well-thought-out approach for Cast devices. The code is generally well-structured.

My review includes a few key points:

  • A critical fix for the video preloading logic, which is currently not functioning due to an incorrect type check.
  • A bug fix in the LocalMediaServer to correctly handle absolute file paths.
  • A suggestion to improve exception handling in the server.
  • A minor refactoring to remove redundant code in the player release logic.
  • A point about using magic numbers in the UI layout.

After addressing these points, the feature should be robust and ready.

@amanc3765 amanc3765 force-pushed the feature/cast-local-media branch from e1d1e13 to f3cbabd Compare February 8, 2026 11:37
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.

1 participant