A simple Android application that demonstrates how to cast video content to a Chromecast device using the Google Cast SDK.
The CastVideoApp allows users to stream video content from their Android devices to a Chromecast-enabled device. This app leverages the Google Cast SDK to provide seamless integration with Chromecast devices.
This project includes:
- A
MediaRouteButton
for connecting to Chromecast devices. - Integration with the Google Cast SDK for media streaming.
- Logging for session management and debugging.
- Connect to Chromecast devices via the
MediaRouteButton
. - Stream video content (MP4 format) to the connected Chromecast device.
- Handle session lifecycle events (start, end, resume, etc.).
- Debugging support for easier development and troubleshooting.
Before running this project, ensure you have the following:
- Android Studio: Version 4.0 or higher.
- SDK Requirements:
- Compile SDK: 34
- Min SDK: 24
- Target SDK: 34
- Chromecast Device: Ensure you have access to a Chromecast device for testing.
- Google Play Services: Ensure your device has Google Play Services installed and up-to-date.
Clone this repository to your local machine using the following command:
git clone https://github.com/shadyashraf174/CastVideoApp.git
- Open Android Studio and select Open an existing Android Studio project.
- Navigate to the cloned repository folder and open it.
Ensure that all dependencies are up-to-date by syncing the Gradle files:
- Open the
build.gradle.kts
file. - Sync the project with Gradle files by clicking File > Sync Project with Gradle Files.
Replace the placeholder Chromecast application ID (CC1AD845
) in the CastOptionsProvider
class with your actual Chromecast application ID:
return CastOptions.Builder()
.setReceiverApplicationId("YOUR_APPLICATION_ID")
.build()
You can obtain your application ID by registering your app in the Google Cast Developer Console.
- Connect your Android device or start an emulator.
- Click the Run button in Android Studio to build and deploy the app.
-
MainActivity.kt
- The main entry point of the application.
- Initializes the
CastContext
and sets up theMediaRouteButton
. - Handles session lifecycle events using a
SessionManagerListener
.
-
CastOptionsProvider.kt
- Provides configuration options for the Google Cast SDK.
- Sets the Chromecast application ID and enables debug logging.
-
AndroidManifest.xml
- Declares necessary permissions (
INTERNET
,ACCESS_NETWORK_STATE
). - Configures metadata for enabling Cast support.
- Defines the
MainActivity
as the launcher activity.
- Declares necessary permissions (
-
activity_main.xml
- Layout file for the main activity.
- Contains a
MediaRouteButton
for connecting to Chromecast devices.
-
build.gradle.kts
- Manages project dependencies and build configurations.
- Includes the Google Cast SDK and other required libraries.
Below is a class diagram representing the key components of the application: