B4A Library External Displays

Android has had official support for external displays since version 4.2.
Prior to version 4.2 some devices had hardware that was capable of outputting a display signal to an external display but control of this output was implemented by the device manufacturer.
Generally the external display would mirror the device's primary display and that was it.

There was no standard API to control external displays until android version 4.2.
Android version 4.2 introduced the Presentation class.
A Presentation is a container for displaying a user interface on an external display.

An external display could now be configured to display any custom user interface - as well as still being able to simply mirror the device's primary display.

An external display is a display that is temporarily connected to a device.
Examples are:
  • TV or projector connected to device using an HDMI cable or MHL adapter.
  • TV or projector connected to device using the Miracast wireless protocol.
    This includes a Samsung device using Samsung's AllShare Cast technology - AllShare Cast is Samsung's proprietary implementation of the Miracast protocol.
  • TV or projector connected to device using a SlimPort cable.

Whereas a primary display is a display that the device normally uses for output.
A TV or projector connected to an android TV stick or OUYA device is still a primary display and not an external display as it is the display that the device normally uses for output.

A Chromecast device is not presently classified as an external display.
A Chromecast device is a media streaming device that can be told to playback a media resource - it will retrieve and display that media resource.
The Chromecast can be told to display a media resource by various methods: an android or iOS application or the desktop Chrome browser can tell a Chromecast device what media resource to display.
But the Chromecast is not currently an external display - i say currently as there is the possibility that Google will update the Chromecast firmware so that it behaves as an external display - but that is just a possibility and may or (more likely) may not happen.

But in this thread i'll publish my attempts to wrap the parts of the android API that allow control over both external displays and Chromecast devices.

If you do not have a device which you can connect to an external display then you are not out of luck - as long as your device is running android 4.2 or later.
In your device's Developer Options under the Drawing category you should find an option to Simulate secondary displays.
Give that option a click and you'll be presented with a list of available emulated secondary displays.
Select an option from that list and a small window will be overlaid on the device display - that small window is a software emulated external display and can be used as an alternative to a real external display.
You can tap and drag the window around the screen so as to not obscure a part of the device's main screen that you need to interact with.

I'll keep this thread tidy by attaching all library files to this first post.

Martin.
 

Attachments

  • CWAC-Presentation_library_files_v0.30.zip
    28.5 KB · Views: 765
  • ExternalDisplays-20140422.zip
    148.4 KB · Views: 891

warwound

Expert
Licensed User
Longtime User
In theory the Chromecast is a remotely controllable browser that supports all the latest browser features.
That assumes $5 allows you to load your own HTML web app.

Anything possible with a browser is possible - notifications and call alerts must be just the tip of an iceberg.
 

moster67

Expert
Licensed User
Longtime User
Martin,

Sweet! I got everything working. Not sure what made it to work, perhaps using the latest android.jar in the B4A-path as you suggested or perhaps the new demo-files you sent.

Now I am playing around and your demo works great although I am struggling to use my own video-source but this is probably something related to the decoding abilities of ChromeCast which are rather limited as of today. Unfortunately I could not find any related error-messages in the logs (filtered and unfiltered). Hopefully I will sort it out by implementing some kind of transcoding of the video-source.
 

PaulR

Active Member
Licensed User
Longtime User
Did you download the 0.3 update from post #1?
Hi, yes I must have edited as you posted there.

I've noticed something from using the new demo app. The displays are....

Built-in Screen
EZCast-050605AC

.... and I disconnected and reconnected to see the ID for EZCast from the service module notification - it was 5. I added the ID to the info in the ListView and on reconnection I have....

Built-in Screen 0
EZCast-050705AC 6

I think the 6 corresponds to the number of times I have told Android to Forget the pairing with the EZCast dongle, which I did that time too (sometimes it doesn't connect without the help of the EZShare app unless I forget the connection and re-search). It would be handy to have the overloaded getDisplays(String category) method to see if it's available as a Presentation display, but maybe CWAC-Presentation is looking for an ID of 1?

What's your EZCast id?

edit: I see that the flags are....

Built-in Screen 3
EZCast-050705AC 0

... which means that the external display doesn't have FLAG_PRESENTATION set?
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Take a look here: http://joaoapps.com/autocast/ This guy seems to be able to cast anything from his Android phone. He actually casts notifications from his phone.

Cheers,
Yes, if you go further, he is also allowing you to make custom screens. You need to be able to use HTML and JS atleast for his system.

What is more interesting is that he allows you to store the screens on dropbox. Sounds to me like he is using custom receivers from within his receiver, thus people can bypass the $5!
 

warwound

Expert
Licensed User
Longtime User
Right i have some info regarding the Chromecast...

I've registered for access to the Google Cast SDK Developer Console, that's the one off $5 fee.

Next registered my Chromecast - simply entered it's serial number into the Developer Console, you have the option to register as many devices as you want it seems.

Wait 15 to 30 minutes - it'll take a little while for your device registration to take effect.

Back in the Developer Console you have the options to add new Applications and can choose Custom Receiver or Styled Media Receiver.
CustomReceiver means 'your very own complete web app' so i choose that.
You have to set a name for your new application and also - the most important bit - the URL that will be loaded when your application is launched.
Also important is the note on the page: Only applications hosted on secure sites (https://) can be published.
You can, by the way, create iOS and Chrome applications in the same Developer Console.

I've now created and enabled a secure site on my VPS - hopefully the OpenSSL will be acceptable to Google.
Now when will i have time to re-learn some HTML/CSS and javascript...?

Martin.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Ok you were quick to splurge out the dope, impulse buyer!
Using HTML/CSS/JS the possibilities are endless, unfortunately I dont know anything about those!
Btw, i thought it is possible to host the receiver on Google Driver (maybe that uses SSL even on public links).

And also, I wrote a shaky wrapper and now I am able to remotely control other apps media sessions!
I cannot control Youtube (still uses the preview SDK not the released one) or Vevo, but I was able to control LocalCast and Cloudcast.
 

thedesolatesoul

Expert
Licensed User
Longtime User

warwound

Expert
Licensed User
Longtime User
Will not work with custom receivers

I found the CastCompanionLibrary and thought it'd make a good b4a library.
It uses the Cast SDK so allows more precise control over the Chromecast including styled and custom receivers.
Unfortunately i can't find a single example android project that uses it, there's no demos just a documentation PDF.
And the PDF doesn't give an entire working example.

I'll look at it more this weekend.

Martin.
 

DSD

Member
Licensed User
Longtime User
I found the CastCompanionLibrary and thought it'd make a good b4a library.
It uses the Cast SDK so allows more precise control over the Chromecast including styled and custom receivers.
Unfortunately i can't find a single example android project that uses it, there's no demos just a documentation PDF.
And the PDF doesn't give an entire working example.

I'll look at it more this weekend.

Martin.

That sounds really good, it looks interesting.
 

warwound

Expert
Licensed User
Longtime User
That sounds really good, it looks interesting.

It encapsulates a lot of function in a small(ish) number of classes and methods so is perfect for a b4a library - just wish i could find some working examples.
 

antonomase

Active Member
Licensed User
Longtime User
Hi

I try one example wich works with an HDMI connexion ant it's OK.

The second one (the one with AdditionalRes appcompat, mediarouter, ...) does not compile :

Compiling generated Java code. Error
B4A line: 53
MediaRouteButton1.SetRouteSelector(MediaRouteSelector1)
javac 1.7.0_25
src\test3\externaldisplaysdemo\main.java:338: error: package android.support.v7.media does not exist
mostCurrent._mediaroutebutton1.SetRouteSelector((android.support.v7.media.MediaRouteSelector)(mostCurrent._mediarouteselector1.getObject()));

is it the example with chromecast ?
 

thedesolatesoul

Expert
Licensed User
Longtime User

antonomase

Active Member
Licensed User
Longtime User
Thanks. I have forgotten the .jar files from support/v7

But I can't test : some problems with the Chromecast device.
First i could not configure it with my tablet Asus (impossible to connect with wifi at 1 meter) but it was fine with my Samsung S3
And now, when the Chromecast device starts, it cannot connect to the wifi router (at 2 meters of it).

It's the first time I have all that problems with wifi.

I will find the solutions tomorrow.

Just a question : is it possible with Chromecast to have the same thing that your other application : a list on the tablet screen and some other views (like a Webview) on the external display ? Or is Chromecast just to display movies ?
 

thedesolatesoul

Expert
Licensed User
Longtime User
I have to say Chromecast is a bandwidth hoarder, it will degrade your wifi performance at least a little.
Try resetting your router and chromecast.

With a chromecast, you cannot view the usual android views. The display on the TV is a receiver which is an HTML file. If you are good in HTML/JS etc you can display things there. But in its usual form it is to display media.
 

antonomase

Active Member
Licensed User
Longtime User
Hi,

I stop Chromecast testing for the moment.

I am testing the CWAC presentation library and it is very usefull.

Just a question about disconnecting / reconnecting the external display during the application is running.
In your example, you start another Activity to show the web sites when the external display is disconnected. And when it is reconnected, I understand that the call of Activity.Finish re-execute PresentationHelper1_ShowPresentation into the main Activity.


I am testing an application (a Timer) :
On the tablet screen : a label with the time, a start button and a stop button
On the external display : a label which duplicate the text of the label on the tablet

When I disconnect the external display, I do not have to create another activity like in the example. There is no external display, that's all.
But without this second activity, how can I detect when the external display is reconnected ?

My test is joined.

Thanks for your help
 

Attachments

  • testdisplay.zip
    7.8 KB · Views: 235

warwound

Expert
Licensed User
Longtime User
@antonomase

Look at this post: http://www.b4x.com/android/forum/threads/external-displays.39861/page-4#post-240157.

The demo project attached to that post should help you establish when an external display is connected or disconnected.
It uses a Service so runs in the background.

The CWAC-Presentation library is based on an android library that aims to simplify connection to an external display.
The simplification takes care of some things for you but also takes away some low level control that you may require.

Adding DisplayManager and DisplayManagerDisplayListener to the library restores that low level control.

Martin.
 

Steve Piehl

Member
Licensed User
Longtime User
Any update on a B4A ChromeCast library? I would was hoping to write a custom "receiver" app that runs on the device itself. Thanks in advance.
 

warwound

Expert
Licensed User
Longtime User
Any update on a B4A ChromeCast library? I would was hoping to write a custom "receiver" app that runs on the device itself. Thanks in advance.

I'm having a break from work and programming at the moment, but have been asked by another forum member to help with creating a simple to use Chromecast library.
The libraries in this thread so far have been an experiment and aren't really complete and ready to use.

My plan is to resume work the week after next - i'll post any Chromecast library updates in this thread, so watch this thread and be patient, a new or updated Chromecast library should be available soon.

Martin.
 
Top