Chromecast - DevParty Torino 2014

15

Click here to load reader

description

Chromecast by Google - Gianluca Arbezzano @ CorleyCloud

Transcript of Chromecast - DevParty Torino 2014

Page 1: Chromecast - DevParty Torino 2014

DEVPARTYGOOGLE CHROMECAST AND ANGULARJS

Created by / Gianluca Arbezzano @gianarb

Page 2: Chromecast - DevParty Torino 2014

WHAT IS THIS?!

Chromecast is a thumb-sized media streaming device that plugsinto the HDMI port on your TV

Page 3: Chromecast - DevParty Torino 2014

SETUPCHROMECAST.COM/SETUP

Page 4: Chromecast - DevParty Torino 2014

DEVELOPER PROGRAMDEVELOPERS.GOOGLE.COM/CAST

Page 5: Chromecast - DevParty Torino 2014

SENDERGOOGLE CAST SUPPORTS SENDER APPLICATIONS WRITTEN

FOR THE ANDROID, IOS, AND CHROME PLATFORMS.

Page 6: Chromecast - DevParty Torino 2014

RECEIVERGOOGLE CAST SUPPORTS SENDER APPLICATIONS WRITTEN

FOR THE ANDROID, IOS, AND CHROME PLATFORMS.

Page 7: Chromecast - DevParty Torino 2014

MY CHROMECAST GENERIC SENDER

sendev-cast.gianarb.it/#/home

Page 8: Chromecast - DevParty Torino 2014

.run(['$window', '$timeout', '$rootScope', '$q', function run ($window, $timeout, $rootScope, $q) { /** * Manage history */ $rootScope.logs = []; /** * Cast is ready?! */ if (!$window.chrome.cast || ! $window.chrome.cast.isAvailable) { var def = $q.defer(); def.resolve(chrome.cast); $rootScope.cast = def.promise; }}])

Page 9: Chromecast - DevParty Torino 2014

$rootScope.cast.then(function(cast){ $window.sessionRequest = new chrome.cast.SessionRequest(appId); $rootScope.configuration.appId = appId; var apiConfig = new chrome.cast.ApiConfig( $window.sessionRequest, $window.sessionListener, $window.receiverListener ); cast.initialize( apiConfig, function(event){ console.log("Good!"); }, function(event){ if(event){ console.log("D'oh"); } } ); });

Page 10: Chromecast - DevParty Torino 2014

$scope.cast = function(){ $rootScope.cast.then(function(cast){ cast.requestSession(function(e){ $window.session = e; }, function(){ console.log("ERROR"); }); });};

Page 11: Chromecast - DevParty Torino 2014

WORK WITH BUS $window.session.sendMessage( namespace, message, function(e){ console.log("OK"); }, function(e){ console.log("error"); });

Page 12: Chromecast - DevParty Torino 2014

WORK WITH MEDIA $scope.loadMedia = function(url){ var onMediaDiscovered = function(how, media) { console.log("new media session ID:" + media.mediaSessionId); $scope.currentMedia = media; };

$rootScope.cast.then(function(cast){ var mediaInfo = new cast.media.MediaInfo(url); mediaInfo.contentType = 'video/mp4'; var request = new chrome.cast.media.LoadRequest(mediaInfo); request.autoplay = true; request.currentTime = 0; session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), function(e){ $rootScope.logs.push({ message: e, type: "error" }); } ); }); };

Page 13: Chromecast - DevParty Torino 2014

BUS RECEIVERvar handlers = { onReady: function(event) { $rootScope.$broadcast("$castOnReady", event); session.setApplicationState("Application status is ready..."); }, onSenderConnected: function(event) { statusConnect = true; $rootScope.$broadcast("$castOnSenderConnected", event); }, onSenderDisconnected: function(event) { $rootScope.$broadcast("$castOnSenderDisconnected", event); if (session.getSenders().length === 0) { window.close(); } }, onSystemVolumeChanged: function(event) { $rootScope.$broadcast("$castOnSystemVolumeChanged", event); }, onMessage: function(event) { $rootScope.$broadcast("$cast-urn:x-cast:com.corley.google.cast", event); messageBus.send(event.senderId, event.data); }};

Page 14: Chromecast - DevParty Torino 2014

session = cast.receiver.CastReceiverManager.getInstance();session.onSenderDisconnected = handlers.onSenderDisconnected;session.onSenderConnected = handlers.onSenderConnected;session.onSystemVolumeChanged = handlers.onSystemVolumeChanged;session.onReady = handlers.onReady;

messageBus = session.getCastMessageBus('urn:x-cast:com.corley.google.cast');messageBus.onMessage = handlers.onMessage;

Page 15: Chromecast - DevParty Torino 2014

THANKS AND GOOD PATY