Download presentation
Presentation is loading. Please wait.
Published byLizbeth O’Neal’ Modified over 8 years ago
1
Developing for Chromecast Cast Companion Library & Custom Receiver Application
2
Kurt Mbanje @ckurtm / peirr.com
3
What is Chromecast?
6
How does it work?
7
Sender application Two components Applications running on a mobile device or laptop Receiver application (HTML, JavaScript, CSS) app running on a Chromecast or other cast compatible device.
8
Sender application Two components Applications running on a mobile device or laptop Receiver application (HTML, JavaScript, CSS) app running on a Chromecast or other cast compatible device.
9
Receiver application
12
Custom Media Receiver 3 Types of receivers Requires application id, DRM Content, Data centric apps Styled Media Receiver Can be styled with CSS files, requires application id Default Media Receiver Does not require application id, can use CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID in your sender if using CCL
13
Custom Receiver
14
www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js Receiver API
15
Simple Custom Receiver LocalCast
16
//[3] handle the payload from the sender function process(json){ console.log('received: ' + json.url); document.getElementById("image").src= json.url; } //[1] get a handle to the receiver manager window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance(); castReceiverManager.onSenderDisconnected = function(event) { console.log('disconnected: ' + event.data); if (window.castReceiverManager.getSenders().length == 0) { //close the app if we have no more connected devices window.close(); } }; //[2] create a CastMessageBus to handle messages for a custom namespace window.messageBus = window.castReceiverManager.getCastMessageBus('urn:x-cast:com.peirr.localcast'); window.messageBus.onMessage = function(event) { var json = JSON.parse(event['data']); //decode the request from sender app window.sender = event.senderId; process(json); } //[4]start the listener window.castReceiverManager.start();
17
Publishing Receiver Application
18
Development Publish to any server & add endpoint to cast console Debug http://RECEIVER-IP-ADDRESS:9222 Production Server has to be secure (https:// ) Google Cast SDK Developer Console https://cast.google.com/publish/ Publishing
19
Development Publish to any server & add endpoint to cast console Debug http://RECEIVER-IP-ADDRESS:9222 Production Server has to be secure (https:// ) Google Cast SDK Developer Console https://cast.google.com/publish/ Publishing
20
Development Publish to any server & add endpoint to cast console Debug http://RECEIVER-IP-ADDRESS:9222 Production Server has to be secure (https:// ) Google Cast SDK Developer Console https://cast.google.com/publish/ Publishing
21
Sender Application
23
Android development options
24
compile "com.android.support:mediarouter-v7:23.3.0" compile 'com.google.android.gms:play-services-cast:8.4.0'
25
compile "com.android.support:mediarouter-v7:23.3.0" compile 'com.google.android.gms:play-services-cast:8.4.0' compile 'com.google.android.libraries.cast.companionlibrary:ccl:2.8.3'
26
Cast Companion Library
27
https://github.com/googlecast/CastCompanionLibrary-android
28
Example: LocalCast https://github.com/ckurtm/LocalCast
30
Initialize CastConfiguration options =new CastConfiguration.Builder("84B70D9D").enableAutoReconnect().enableDebug().build(); DataCastManager.initialize(this,options);
31
Cast Button <item android:id="@+id/action_cast" android:title="@string/action_cast" app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider" app:showAsAction="always"/> @Override public boolean onCreateOptionsMenu(Menu menu){ super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.menu,menu); DataCastManager.getInstance().addMediaRouterButton(menu,R.id.action_cast); return true; }
32
Send data to Receiver Application JSONObject obj = new JSONObject(); String url = "http://"+ info.ip + ":" + info.port + "/" + item.getFile().getAbsolutePath(); Log.d(TAG, "casting: " + url); try { obj.put("url",url); DataCastManager.getInstance().sendDataMessage(obj.toString(),"urn:x- cast:com.peirr.localcast"); } catch (JSONException|IOException e) { e.printStackTrace(); }
33
Questions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.