Here then is a chance to see what i've been working on the past few days.
It's not intended to be a finished library ready for production use, neither is any of it's syntax and usage guaranteed to remain.
There's a lot of and features and possibilities to cover in this library and i want to keep a balance between endless wrapped classes (that in theory allow complete use of the android API) and simpler helper classes that encapsulate more limited use of the android API but make things so much simpler to use...
In the attchement there are folders:
- 20140420 contains the b4a demo project.
- cwac-mediarouter-res contains android resources needed by one of the android library that this b4a library uses.
- library_files contains the ExternalDisplay library files and an HTML reference document.
Unzip all folders, add the ExternalDisplays library files (.jar and .xml) to your b4a additional libraries folder and open the b4a project.
First locate these lines in the Main Activity (lines 8 to 11):
Code:
#AdditionalRes: C:\Users\martin\Programming\adt-bundle-windows-x86_64-20131030\sdk\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#AdditionalRes: C:\Users\martin\Programming\adt-bundle-windows-x86_64-20131030\sdk\extras\android\support\v7\mediarouter\res, android.support.v7.mediarouter
#AdditionalRes: C:\Users\martin\Programming\adt-bundle-windows-x86_64-20131030\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#AdditionalRes: C:\Users\martin\Programming\Basic4Android\ExternalDisplays\cwac-mediarouter-res, com.commonsware.cwac.mediarouter
The library depends on 3 external android library projects:
(cwac.mediarouter is compiled into the b4a library but still requires you to include it's resources).
- Android Support V4 - android-support-v4
- Android Support V7 AppCompat - android-support-v7-appcompat.jar
- Android Support V7 MediaRouter - android-support-v7-mediarouter.jar
So probably a good idea to start up the android SDK manager and make sure that you have all three library projects installed
and that the latest versions of the .jar files are in your b4a additional libraries folder.
Update the paths to the 'res' folders of each project in the Main Activity - that's the AdditionalRes lines above.
Now you can compile the b4a project, if all goes well you'll see an Activity with the 'Cast' Button top left with a Panel underneath.
The Panel contains an EditText and Buttons for Play, Pause and Stop.
Click the Cast button and if your android device can detect a Chromecast device you'll see a dialog allowing you to select your Chromecast.
Select your Chromecast and take a look at the log, you'll see info about a RouteSelected event being raised, info about whether your Chromecast supports remote playback and session management and then a SessionActionResult event is raised and the logs shows the session id.
The Play, Pause and Stop Buttons (previously disabled) should now be enabled.
Click the Play Button and you should see your Chromecast start to stream a video from the internet.
Try Pause - does it pause playback? And does it resume playback when clicked a second time?
Does Stop stop playback?
Click the Cast Button again and you should have options to adjust the Chromecast volume and also to disconnect.
Finally the ActionBar 'Debug' menu item will force the display of the dialog that appears when you click the Cast Button.
If your android device cannot detect any nearby Chromecast devices then the Cast Button will not activate itself, the Debug menu item forces the Cast Button 'click action' even if it's disabled.
That's about it.
Be sure to look through the HTML reference document - many objects exist as 'stubs' only and have no methods or properties except an 'IsInitialized' method.
I'm hoping that i can develop the ExternalDisplays library so that it supports 'proper' external displays (think HDMI and MHL connections) as well as Chromecast.
Let me have some feedback and we can decide what's the best way forward.
Do we want lots of classes wrapped into lots of b4a objects, and the b4a developer has to study the android APIs and learn how to use these wrapped classes?
Or do we want simpler b4a helper objects that make development much easier but at the same time limit full access to the android APIs?
Martin.