【发布时间】:2015-08-19 01:38:54
【问题描述】:
我正在按照这些(1、2)指南为 Chromecast 创建一个发送者 Android 应用程序,我只对发送图片感兴趣。 有很多信息和samples 如何投射文本、音频和视频。但没有一个字如何使用图片。
我相信 stackoferflow 的力量,应该有人遇到过这样的问题。请提供一些好的示例或教程。我需要的只是使用Media Router 及其功能投射全屏图片的指南。
这就是我使用自定义频道发送短信的方式:
/**
* 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();
}
}
视频正在使用RemotePlaybackClient发送。好的,图片呢?
非常感谢您的帮助。
编辑:
我找到了方法(on this blog) 如何从本地存储发送图片。是的,这似乎并不奏效。
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);
}
}
附:此方法使用这些库中的sendMessage(...)(来自 gradle):
compile files('libs/commons-io-2.4.jar')
compile files('libs/GoogleCastSdkAndroid.jar')
【问题讨论】:
标签: android casting chromecast google-cast