SlideShare a Scribd company logo
DEVPARTY
GOOGLE CHROMECAST AND ANGULARJS
Createdby /GianlucaArbezzano @gianarb
WHAT IS THIS?!
Chromecastis athumb-sized mediastreamingdevice thatplugs
into the HDMI porton your TV
SETUP
CHROMECAST.COM/SETUP
DEVELOPER PROGRAM
DEVELOPERS.GOOGLE.COM/CAST
SENDER
GOOGLE CAST SUPPORTS SENDER APPLICATIONS WRITTEN
FOR THE ANDROID, IOS, AND CHROME PLATFORMS.
RECEIVER
GOOGLE CAST SUPPORTS SENDER APPLICATIONS WRITTEN
FOR THE ANDROID, IOS, AND CHROME PLATFORMS.
MY CHROMECAST GENERIC SENDER
sendev-cast.gianarb.it/#/home
.run(['$window','$timeout','$rootScope','$q',functionrun($window,$timeout,$ro
otScope,$q){
/**
*Managehistory
*/
$rootScope.logs=[];
/**
*Castisready?!
*/
if(!$window.chrome.cast||!$window.chrome.cast.isAvailable){
vardef=$q.defer();
def.resolve(chrome.cast);
$rootScope.cast=def.promise;
}
}])
$rootScope.cast.then(function(cast){
$window.sessionRequest=newchrome.cast.SessionRequest(appId);
$rootScope.configuration.appId=appId;
varapiConfig=newchrome.cast.ApiConfig(
$window.sessionRequest,
$window.sessionListener,
$window.receiverListener
);
cast.initialize(
apiConfig,
function(event){
console.log("Good!");
},
function(event){
if(event){
console.log("D'oh");
}
}
);
});
$scope.cast=function(){
$rootScope.cast.then(function(cast){
cast.requestSession(function(e){
$window.session=e;
},function(){
console.log("ERROR");
});
});
};
WORK WITH BUS
$window.session.sendMessage(
namespace,
message,
function(e){
console.log("OK");
},
function(e){
console.log("error");
}
);
WORK WITH MEDIA
$scope.loadMedia=function(url)
{
varonMediaDiscovered=function(how,media){
console.log("newmediasessionID:"+media.mediaSessionId);
$scope.currentMedia=media;
};
$rootScope.cast.then(function(cast){
varmediaInfo=newcast.media.MediaInfo(url);
mediaInfo.contentType='video/mp4';
varrequest=newchrome.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"
});
}
);
});
};
BUS RECEIVER
varhandlers={
onReady:function(event){
$rootScope.$broadcast("$castOnReady",event);
session.setApplicationState("Applicationstatusisready...");
},
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",even
t);
messageBus.send(event.senderId,event.data);
}
};
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;
THANKS AND GOOD PATY

More Related Content

Chromecast - DevParty Torino 2014