I'm following these (1, 2) guides to create a sender Android application for Chromecast and I'm only interested in sending pictures. There are a lot of informaton and samples how to cast Text, Audio and Video. But not a single word how to that with Pictures.
I belive in power of stackoferflow and someone should've faced such problem. Please give some good sample or tutorial. All I need is guide to cast fullscreen picture using Media Router
and its features.
Thats how I was sending text message using custom channel:
/**
* Send a text message to the receiver
*/
private void sendMessage(String message) {
if (mApiClient != null && mSmartBusChannel != null) {
try {
Cast.CastApi.sendMessage(mApiClient,
mSmartBusChannel.getNamespace(), message)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (!result.isSuccess()) {
Log.e(TAG, "Sending message failed");
}
}
});
} catch (Exception e) {
Log.e(TAG, "Exception while sending message", e);
}
} else {
Toast.makeText(this, message, Toast.LENGTH_SHORT)
.show();
}
}
Video is sending using RemotePlaybackClient
.. Okay, what's about pictures?
Much thanks for any help.
EDIT:
I have found out method (on this blog) of how it is possible to send pictures from local storage. And yeah, that doesn't seem really working.
public final void openPhotoOnChromecast(String title, String url, String ownerName, String description) {
try {
Log.d(TAG, "openPhotoOnChromecast: " + url);
JSONObject payload = new JSONObject();
payload.put(KEY_COMMAND, "viewphoto");
payload.put("fullsizeUrl", url);
payload.put("ownerName", ownerName);
payload.put("title", title);
payload.put("description", description);
sendMessage(payload);
} catch (JSONException e) {
Log.e(TAG, "Cannot parse or serialize data for openPhotoOnChromecast", e);
} catch (IOException e) {
Log.e(TAG, "Unable to send openPhotoOnChromecast message", e);
} catch (IllegalStateException e) {
Log.e(TAG, "Message Stream is not attached", e);
}
}
P.S. this method uses sendMessage(...)
from these libraries (from gradle):
compile files('libs/commons-io-2.4.jar')
compile files('libs/GoogleCastSdkAndroid.jar')
Open the Google Home app > Chromecast > Personalize Ambient, and choose between Google Photos and Art Gallery. Select the Google Photos option to display your photos. Select Art Gallery to use Google-curated images, and select from a variety of categories.
Select Chromecast as the device to use. After this, the entire computer or the browser tab will show on the TV. Select the images you want to cast and it will now be easier for you.
Looking here: Examples using CastCompanionLibrary to simply display an image There are really three options for sending images to a Chromecast.
The goal of Chromecast, according to Google, is to stream content from the cloud, which is why there isn't really any native support for sending local images. Developers should be encouraged to load images on the receiver application from a server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With