问题
When I wrote a simple Chrome (Browser) Chromecast app in the beta a few months ago, I was able to get a list of receivers through Javascript, and then prompt the user to select the device.
Now I can't seem to do this, and I can't figure out how to do this by reading the API docs. It seems that the only thing I can do is hope and pray that my user figures out how to click the chromecast button in the browser.
Youtube, however, has a chromecast button right next to the video. I'd like to do the same thing, via Javascript!
How do I do this?
回答1:
With the new Chrome Sender Cast SDK, this call
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
will always trigger the Cast extension to open a pop-up with a list of devices for users to select and open a session. There won't be a list of device IDs returned to your app that developers can iterate though.
How to trigger this call is up to developers and depend on your use case. You have the following options. - Have a clickable Cast icon like YouTube that users click that triggers this call and then users see the pop-up to the top right corner associated with the Cast extension - Trigger this call upon your page load if your app is all about Cast and wants users to select a device right away - Don't do anything special to trigger this call. In this case when users click on the Cast extension icon, they can select and connect to a Cast device. From there, users can do tab mirror if your page has no Cast integration or a Cast session will be created (or connected to when existing) if you initialize Cast API upon page load.
来源:https://stackoverflow.com/questions/21926127/i-used-to-be-able-to-get-a-receiver-list-in-the-chromecast-beta-now-i-cant