{"id":28500762,"url":"https://github.com/kaltura/playkit-android-googlecast","last_synced_at":"2025-07-04T10:31:17.046Z","repository":{"id":33894356,"uuid":"112586351","full_name":"kaltura/playkit-android-googlecast","owner":"kaltura","description":" Google Cast support for PlayKit Android","archived":false,"fork":false,"pushed_at":"2025-05-28T09:04:57.000Z","size":211,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":19,"default_branch":"develop","last_synced_at":"2025-06-08T15:07:42.646Z","etag":null,"topics":["android","cast","kaltura","playkit"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaltura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-30T08:36:57.000Z","updated_at":"2024-12-23T12:30:51.000Z","dependencies_parsed_at":"2023-11-23T15:30:44.513Z","dependency_job_id":"8a04cea9-76d4-42d3-a800-bdd02d25fc08","html_url":"https://github.com/kaltura/playkit-android-googlecast","commit_stats":null,"previous_names":[],"tags_count":77,"template":false,"template_full_name":null,"purl":"pkg:github/kaltura/playkit-android-googlecast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaltura%2Fplaykit-android-googlecast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaltura%2Fplaykit-android-googlecast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaltura%2Fplaykit-android-googlecast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaltura%2Fplaykit-android-googlecast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaltura","download_url":"https://codeload.github.com/kaltura/playkit-android-googlecast/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaltura%2Fplaykit-android-googlecast/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263492786,"owners_count":23475073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cast","kaltura","playkit"],"created_at":"2025-06-08T15:07:42.992Z","updated_at":"2025-07-04T10:31:17.014Z","avatar_url":"https://github.com/kaltura.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI Status](https://github.com/kaltura/playkit-android-googlecast/actions/workflows/build.yml/badge.svg)](https://github.com/kaltura/playkit-android-googlecast/actions/workflows/build.yml)\n[![Download](https://img.shields.io/maven-central/v/com.kaltura.playkit/googlecast?label=Download)](https://search.maven.org/artifact/com.kaltura.playkit/googlecast)\n[![License](https://img.shields.io/badge/license-AGPLv3-black.svg)](https://github.com/kaltura/playkit-android-kava/blob/master/LICENSE)\n![Android](https://img.shields.io/badge/platform-android-green.svg)\n\n# playkit-android-googlecast\n\nUsing the Google Cast plugin, Developers can extend the media to another TV, Audio system etc. It will be a remote media streaming and your app will become a remote for it.\n\nWe provide Cast Application Framework(CAF) for it. Our plugin is developed on top of Google's designed CAF framework.\n\nBefore understanding that how to setup Google cast plugin on Android, let's understand few terms,\n\n##### Sender Application: \nYour Android app which gives the user the ability to connect to the casting device, is a Sender Application.\n\n##### Receiver Application:\nWhen your sender app connects to the cast device then cast device downloads an script from the server which is actually configured against the CastId for your application. Basically it's a Web receiver Application. [How to build a Receiver Application](https://github.com/kaltura/playkit-js-cast-receiver)\n\n##### Cast Receiver ID: \nTo register the receiver application, Developers has to register on [Google Cast SDK Developer Console](https://cast.google.com/publish). \nThis receiver ID is the gateway for the sender app to communicate with the remote receiver app.\n\n### Setup\n\nAdd GoogleCast plugin dependency to `build.gradle`. In android, we keep all plugins aligned with same version.\n\n`implementation 'com.kaltura.playkit:googlecast:x.x.x'`\n\n**You can find the latest version here:**\n\n[Latest Release](https://github.com/kaltura/playkit-android-googlecast/releases)\n\n### How to use Google Cast plugin\n\n##### 1. Create `CastContext`\n\n`mCastContext = CastContext.getSharedInstance(this)`\n\n##### 2. Create `SessionManagerListener` \n\nA `Session` is a connection between Sender and Receiver Application. [More Info](https://developers.google.com/android/reference/com/google/android/gms/cast/framework/Session?hl=en)\n\n```kotlin\nmCastContext?.sessionManager?.addSessionManagerListener(\n                mSessionManagerListener, CastSession::class.java)\n```\n\nIn this, `onApplicationConnected` of `SessionManagerListener` callback will help application to load the media.\n\n##### 3. Get `RemoteMediaClient`,\n\nApp will get `remoteMediaClient` in the callback `onSessionResumed` of `SessionManagerListener`. Once app get the `remoteMediaClient` then register the  listener for `RemoteMediaClient.Callback()`. \n\nThis listener has a callback `onStatusUpdated` where we will know that there is a nearby casting device and app can connect to that.\n\n##### 4. Getting the Cast icon and the remote controller activity for the App\n\nHere comes an important step, how the user will get the cast icon, \n\nA menu item can be added for and `Activity`,\n\n```xml\n\u003citem\n        android:id=\"@+id/media_route_menu_item\"\n        android:title=\"@string/media_route_menu_title\"\n        app:actionProviderClass=\"androidx.mediarouter.app.MediaRouteActionProvider\"\n        app:showAsAction=\"always\"/\u003e\n\n```\t \n\nThis will enable a cast icon in the tool bar menu item.\n\nFor the expanded controller for the receiver application. Launch an activity which extents to Cast framework class `ExpandedControllerActivity`. \nThen in this activity's menu inflation method, app has to setup the `MediaRouteButton`,\n\n```kotlin\noverride fun onCreateOptionsMenu(menu: Menu): Boolean {\n        super.onCreateOptionsMenu(menu)\n        menuInflater.inflate(R.menu.expanded_controller, menu)\n        CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item)\n        return true\n    }\n\n```\n\nThis new acitivity should be launched in ``onStatusUpdated` callback of `RemoteMediaClient.Callback()` on `remoteMediaClient`,\n\n```kotlin\nremoteMediaClient!!.registerCallback(object : RemoteMediaClient.Callback() {\n            override fun onStatusUpdated() {\n                val intent = Intent(this@MainActivity, ExpandedControlsActivity::class.java)\n                startActivity(intent)\n                //remoteMediaClient?.unregisterCallback(this)\n            }\n            ...\n            ...\n\n```\n##### 5. Load the Media for Casting\n\n###### GoogleCast for Kaltura OTT Customers\n\n```kotlin\nval castBuilder = KalturaPhoenixCastBuilder()\n                .setMediaEntryId(mediaId)\n                .setKs(\"\")\n                .setFormats(formats)\n                .setStreamType(CAFCastBuilder.StreamType.VOD)\n                .setAssetReferenceType(CAFCastBuilder.AssetReferenceType.Media)\n                .setContextType(CAFCastBuilder.PlaybackContextType.Playback)\n                .setMediaType(CAFCastBuilder.KalturaAssetType.Media)\n                .setProtocol(protocol)\n\nvar mediaInfo: MediaInfo = castBuilder.build()\n\n```\n\n###### GoogleCast for Kaltura OVP Customers\n\n```kotlin\nval castBuilder = KalturaCastBuilder()\n                .setMediaEntryId(entryId)\n                .setKs(\"\")\n                .setStreamType(CAFCastBuilder.StreamType.VOD)\nvar mediaInfo: MediaInfo = castBuilder.build()\n\n```\n\n###### GoogleCast for Non Kaltura Customers (Basic Cast Provider)\n\n```Kotlin\nval castBuilder = KalturaBasicCAFCastBuilder(playbackParams)\n                .setStreamType(CAFCastBuilder.StreamType.VOD)\nvar mediaInfo: MediaInfo = castBuilder.build()\n\n```\n\n\u003e How to create `PlaybackParams` for Non-Kaltura Customers \n\n```kotlin\n        val playbackParams = PlaybackParams();\n        playbackParams.poster = \"Poster_URL\"\n        playbackParams.id = \"ID\"\n        playbackParams.duration = Duration\n        playbackParams.type = \"Vod\" // For Live \"Live\" can be set\n        playbackParams.dvr = false\n        playbackParams.vr = null\n        \n\t\t // If DASH Widevine source is required \n        playbackParams.setDashSource(\"ID\",\"PlaybackURL\",\"LicenseURL\")\n        \n        // For Clear DASH\n        // playbackParams.setDashSource(\"ID\",\"URL\",\"\") // Pass empty License URL\n        \n        // Another way of passing clear DASH media\n        // val drmData = DrmData() // This is important to be passed\n        // drmData.licenseUrl = \"\" // Empty License URL\n        // drmData.scheme = PlaybackParams.DRMSCHEME_WIDEVINE\n        // playbackParams.dash = listOf(Dash(\"ID\",\"PlaybackURL\", PlaybackParams.MIMETYPE_DASH, drmData))\n        \n\n        // If HLS source is required \n        // playbackParams.setHlsSource(\"ID\",\"PlaybackURL\")\n        \n        // Another way of passing HLS Source\n        // val hlsSource = Hls()\n        // hlsSource.id = \"ID\"\n        // hlsSource.url = \"PlaybackURL\"\n        // hlsSource.mimetype = PlaybackParams.MIMETYPE_HLS\n        // playbackParams.hls = listOf(hlsSource)\n        \n\n\t\t// If Progressive Source (Ex. mp4) is required\n        // playbackParams.setProgressivehSource(\"ID\",\"PlaybackURL\")\n        \n        // Another way of passing Progressive Source\n        // val progressiveSource = Progressive();\n        // progressiveSource.id = \"ID\";\n        // progressiveSource.url = \"PlaybackURL\";\n        // progressiveSource.mimetype = PlaybackParams.MIMETYPE_MP4;\n        // playbackParams.progressive = listOf(progressiveSource)\n\n        val metadata: Metadata = Metadata()\n        metadata.description = \"\" // Description Text which will be visible on the media on Cast device\n\n        metadata.name = \"Text Tracks\" // Title Text which will be visible on the media on Cast device\n        metadata.tags = \"\";\n        playbackParams.metadata = metadata\n        playbackParams.captions =  // Pass external captions (How to build it is given in the next part of the document)\n\n```\n\n##### 6. Create `MediaLoadOptions` before actually loading the media using `RemoteMediaClient`\n\n```kotlin\nvar pendingResult: PendingResult\u003cRemoteMediaClient.MediaChannelResult\u003e? = null\nval loadOptions = MediaLoadOptions.Builder().setAutoplay(true).setPlayPosition(0L).build()\n\n```\n\u003e **NOTE: In case for Live Media, `setPlayPosition` should be passed `MediaInfoUtils.LIVE_EDGE` or `-1L`**. \n\u003e \n\u003e **In case, for VOD assets, app wants to pass the start position for the player, this parameter can be used.**\n\n##### 7. Finally load the `RemoteMediaClient`,\n\n```kotlin\npendingResult = remoteMediaClient!!.load(mediaInfo object, loadOptions)\n\n```\n\n#### Play Ads with Google Cast\n\nFor VAST Ad URL, pass AdUrl in `MediaInfoUtils`,\n\n`val adsConfig = MediaInfoUtils.createAdsConfigVastInPosition(startPosition, adTagUrl)`\n\nFor VMAP, pass AdUrl like this,\n\n`val adsConfig = MediaInfoUtils.createAdsConfigVmap(adTagUrl)`\n\nFor VAST Ad response XML, pass ad response to\n\n`MediaInfoUtils.createAdsResponseConfigVastInPosition(startPosition, adResponse)`\n\nFor VMAP Ad response XML, pass ad response to\n\n`MediaInfoUtils.createAdResponseConfigVmap(adResponse)`\n\nThen pass the `AdsConfig` object to `setAdsConfig` on the respective cast builder object (OTT/OVP or Basic)\n\n**OTT:** `phoenixCastBuilder.setAdsConfig(Ads_Config)`\n\n**OVP:** `ovpV3CastBuilder.setAdsConfig(Ads_Config)`\n\n**BASIC:**`basicCastBuilder.setAdsConfig(Ads_Config)`\n\n`startPosition` is the cast player start position. Let's suppose media is playing back at some position x seconds and when the user connects then app want to media to start from x seconds then use this parameter. This is only meant for VAST ad url/response. It will be one time ad playback.\n\nFor VMAP, anyways based on the time offset given in the VMAP, ads will be played.\n\n\u003e **NOTE : We have [IMA Plugin](https://github.com/kaltura/playkit-android-ima) for Ad playback. That is only meant for in app Ad playback. IMA Plugin does not help to play the Ads while using the cast.**\n\n\u003e **For Cast the above given configuration is must to have otherwise Ad will not play in GoogleCast.**\n\n\n#### Pass External Subtitles for the media\n\nCreate a list of `Caption` object,\n\n```kotlin\nprivate fun getExternalVttCaptions(): List\u003cCaption\u003e {\n        val caption1 = Caption()\n        caption1.isDefault = false\n        caption1.type = \"vtt\"\n        caption1.label = \"Heb\"\n        caption1.language = \"he\"\n        caption1.url = \"subtitle_url\"\n        val caption2 = Caption()\n        caption2.isDefault = false\n        caption2.type = \"vtt\"\n        caption2.label = \"Jap\"\n        caption2.language = \"ja\"\n        caption2.url = \"subtitle_url\"\n        val caption3 = Caption()\n        caption3.isDefault = false\n        caption3.type = \"vtt\"\n        caption3.label = \"Rus\"\n        caption3.language = \"ru\"\n        caption3.url = \"subtitle_url\"\n        var captions: List\u003cCaption\u003e = mutableListOf(caption1, caption2, caption3)\n        return captions\n    }\n```\n\nAnd then pass this to the respective cast builder object,\n\n`phoenixCastBuilder.setExternalVttCaptions(getExternalVttCaptions())`\n\n#### Next Media Playback (Change Media)\n\nSimply load the next media given in **Step - 7** above. \n\n### Samples:\n\n[Kaltura Player Google Cast Sample](https://github.com/kaltura/kaltura-player-android-samples/tree/develop/AdvancedSamples/ChromecastCAFSample)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaltura%2Fplaykit-android-googlecast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaltura%2Fplaykit-android-googlecast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaltura%2Fplaykit-android-googlecast/lists"}