Created
March 12, 2016 16:06
-
-
Save anonymous/6b0eb6a582677a9decf0 to your computer and use it in GitHub Desktop.
Google Cast (Chromecast) JavaScript API custom URL sender sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src='https://www.gstatic.com/cv/js/sender/v1/cast_sender.js'></script> | |
<script> | |
function onError() { | |
document.getElementById('message').innerHTML = 'Error'; | |
} | |
window['__onGCastApiAvailable'] = function(loaded, errorInfo) { | |
if (loaded) { | |
var applicationID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID; | |
var sessionRequest = new chrome.cast.SessionRequest(applicationID); | |
var apiConfig = new chrome.cast.ApiConfig(sessionRequest, function() {}, function() {}); | |
chrome.cast.initialize(apiConfig, | |
function(message) { | |
document.getElementById('castButton').disabled = false; | |
}, onError); | |
} | |
} | |
function cast() { | |
url = document.getElementById('url').value; | |
if (!url) return; | |
chrome.cast.requestSession(function(session) { | |
var mediaInfo = new chrome.cast.media.MediaInfo(url); | |
mediaInfo.contentType = 'video/mp4'; | |
// mediaInfo.contentType = 'audio/mpeg'; | |
// mediaInfo.contentType = 'image/jpeg'; | |
var request = new chrome.cast.media.LoadRequest(mediaInfo); | |
request.autoplay = true; | |
session.loadMedia(request, function() {}, onError); | |
}, onError); | |
} | |
</script> | |
</head> | |
<body> | |
<div> | |
<input type='text' size='70' id='url' value='https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'></input> | |
<input type='button' onclick='cast()' value='Cast' id='castButton' disabled></input> | |
<div id='message'></div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment