From aab39332755cf68abf9cf6dba1a4657984ba2ec5 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 4 Apr 2014 16:38:36 +0200 Subject: [PATCH] Cast API --- api.php | 16 ++-- cast.js | 90 +++++++++++++++++++++ head.php | 2 + img/ic_media_route_disabled_holo_light.png | Bin 0 -> 380 bytes img/ic_media_route_off_holo_light.png | Bin 0 -> 401 bytes img/ic_media_route_on_holo_light.png | Bin 0 -> 439 bytes style.css | 12 +++ 7 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 cast.js create mode 100644 img/ic_media_route_disabled_holo_light.png create mode 100644 img/ic_media_route_off_holo_light.png create mode 100644 img/ic_media_route_on_holo_light.png diff --git a/api.php b/api.php index 89952c2..3b233b1 100644 --- a/api.php +++ b/api.php @@ -1,9 +1,9 @@ @@ -15,7 +15,7 @@ require_once 'download.php'; if (isset($_GET["url"])) { if (isset($_GET["format"]) || isset($_GET['audio'])) { $video = VideoDownload::getJSON($_GET["url"], $_GET["format"]); - + if (isset($video->url)) { //Vimeo needs a correct user-agent $UA = VideoDownload::getUA(); @@ -57,7 +57,7 @@ if (isset($_GET["url"])) { ); exit; } - + } else { if (isset($_GET['audio'])) { header( @@ -135,12 +135,12 @@ if (isset($_GET["url"])) { include 'logo.php'; ?>

You are going to download - + title; - ?>.

+ ?>. Google Cast™ is disabledGoogle Cast™Casting to ChromeCast…

thumbnail, '" alt="" />'; ?>
@@ -184,7 +184,7 @@ if (isset($_GET["url"])) { $error=true; } } -} +} if (isset($error)) { include 'head.php'; ?> diff --git a/cast.js b/cast.js new file mode 100644 index 0000000..d406aa6 --- /dev/null +++ b/cast.js @@ -0,0 +1,90 @@ +/*global chrome*/ +/*jslint devel: true, browser: true */ +var launchBtn, disabledBtn, stopBtn; +var session, currentMedia; + +function receiverListener() { + 'use strict'; + console.log('receiverListener'); +} + +function sessionListener() { + 'use strict'; + console.log('sessionListener'); +} + +function onMediaDiscovered(how, media) { + 'use strict'; + currentMedia = media; +} + +function onMediaError() { + 'use strict'; + console.log('onMediaError'); + stopCast(); +} + +function onRequestSessionSuccess(e) { + 'use strict'; + session = e; + var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo); + stopBtn.classList.remove('cast_hidden'); + launchBtn.classList.add('cast_hidden'); + session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError); +} + +function onLaunchError() { + 'use strict'; + console.log('onLaunchError'); +} + +function onInitSuccess() { + 'use strict'; + chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError); +} + +function onError() { + 'use strict'; + console.log('onError'); +} + +function onStopCast() { + 'use strict'; + stopBtn.classList.add('cast_hidden'); + launchBtn.classList.remove('cast_hidden'); +} + +function launchCast() { + 'use strict'; + var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.PAGE_SCOPED); + chrome.cast.initialize(apiConfig, onInitSuccess, onError); +} + +function stopCast() { + 'use strict'; + session.stop(onStopCast); +} + +function initializeCastApi() { + 'use strict'; + launchBtn = document.getElementById('cast_btn_launch'); + disabledBtn = document.getElementById('cast_disabled'); + stopBtn = document.getElementById('cast_btn_stop'); + if (launchBtn) { + disabledBtn.classList.add('cast_hidden'); + launchBtn.classList.remove('cast_hidden'); + launchBtn.addEventListener('click', launchCast, false); + stopBtn.addEventListener('click', stopCast, false); + } +} + +function loadCastApi(loaded, errorInfo) { + 'use strict'; + if (loaded) { + initializeCastApi(); + } else { + console.log(errorInfo); + } +} + +window['__onGCastApiAvailable'] = loadCastApi; diff --git a/head.php b/head.php index 40dbf08..1ecc7e0 100644 --- a/head.php +++ b/head.php @@ -21,6 +21,8 @@ href="https://fonts.googleapis.com/css?family=Open+Sans:400,300" /> + + diff --git a/img/ic_media_route_disabled_holo_light.png b/img/ic_media_route_disabled_holo_light.png new file mode 100644 index 0000000000000000000000000000000000000000..319c57e8f343f22b12799ab91937eac20ca6eb80 GIT binary patch literal 380 zcmV-?0fYXDP)L{ot;E?S6hQ`J zR3c>RCCH0(>C~m`{>WYJ67&az5_kw16V!u;Li1RH=KKzxLx%>@*j^9s3m;yX41e#l z=b2~*L13s{2ZrLM1Ly$C17v=?=s3=OQeWu0Zg>AH@MCrVdCEUmRX3py5Y>dwC@QG{ z-Dwd`M*VuJ59dtih)EYxueJGB73L_Fz%Cpo<(RjH=c19xm!IKnG>*x(YC zw8pTE8#Lr`^sz+?xugR;;zcIm98E0X;}91~Pr;dV|5B=Oig%19P*|NI3TQ|CoX4s_ zSoRLq7|6AnjN+TzQ^E&=Bq|WDeAx9&gwJU{<+NFO6el?5vl;tC+yJKjW1<7-0ICD* a1Q-BA!9d^IFiXz>000085Sl%Fd?aIM)B~z^1fxW#74k*@Py* zE}JlcxRwsE+b=0^XzE&mM?B+|Fm(jI4seGdj&Y9{LZnm$uzveT#H2@*YZPVB8ru85 zi2i&PGw})oE>HP#nR0=|y3*}f z%65Q%oDQSi0nevE2WWQpF)&XT{DQ4h0ioBfS!<*DNzHy2b1neJgh25n#(gQ!_qNo{w4Z4Ar!#11a_(lzw}LpZ_<2IPmWu+;%`j`Pxm2TUT0 z8@yu}6PUxL6OUuF?f0l-RraOvBe!S(OA@H*)Jhn}E@=