A Pen by Yusei Yamanaka on CodePen.
Created
February 12, 2022 01:29
-
-
Save HeNy007/c84147809ec62dff02863a47783fca1b to your computer and use it in GitHub Desktop.
Chromecast 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
| <html> | |
| <head> | |
| <script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script> | |
| </head> | |
| <body> | |
| <button class="button">Loading</button> | |
| </body> | |
| </html> |
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
| var initializeCastApi = function() { | |
| console.log('initializeCastApi'); | |
| var sessionRequest = new chrome.cast.SessionRequest( | |
| chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID); | |
| var apiConfig = new chrome.cast.ApiConfig( | |
| sessionRequest, sessionListener, receiverListener); | |
| chrome.cast.initialize(apiConfig, onInitSuccess, onError); | |
| }; | |
| if (!chrome.cast || !chrome.cast.isAvailable) { | |
| setTimeout(initializeCastApi, 1000); | |
| } | |
| function onInitSuccess() { | |
| console.log('onInitSuccess'); | |
| } | |
| function onError(e) { | |
| console.log('onError', e); | |
| } | |
| function sessionListener(e) { | |
| console.log('sessionListener', e); | |
| } | |
| function receiverListener(availability) { | |
| console.log('receiverListener', availability); | |
| if(availability === chrome.cast.ReceiverAvailability.AVAILABLE) { | |
| $(".button").removeAttr("disabled").text("Start"); | |
| } | |
| } | |
| function onSessionRequestSuccess(session) { | |
| console.log('onSessionRequestSuccess', session); | |
| var mediaInfo = new chrome.cast.media.MediaInfo( | |
| "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", | |
| "video/mp4"); | |
| var request = new chrome.cast.media.LoadRequest(mediaInfo); | |
| session.loadMedia(request, onMediaLoadSuccess, onError); | |
| } | |
| function onMediaLoadSuccess(e) { | |
| console.log('onMediaLoadSuccess', e); | |
| } | |
| $(".button").click(function() { | |
| chrome.cast.requestSession(onSessionRequestSuccess, onError); | |
| }); |
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
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment