我正在为应用程序Narwhal TV添加chromecast支持以获取reddit https://play.google.com/store/apps/details?id=org.elsewhat.reddit&hl=en
由于它汇总了在reddit上流行的YouTube视频,我想重复使用youtube chromecast接收器应用。
我已经取得了一些进展:我可以连接到chromecast设备并启动youtube应用。 但是,我无法开始播放视频。大部分进展都归功于castv2-youtube项目https://github.com/xat/castv2-youtube
启动youtube应用程序
private String CHROMECAST_APP_ID="233637DE";
Cast.CastApi.launchApplication(mApiClient, CHROMECAST_APP_ID, false)
定义youtube频道
class YoutubeChannel implements Cast.MessageReceivedCallback {
public String getNamespace() {
return "urn:x-cast:com.google.youtube.mdx";
}
@Override
public void onMessageReceived(CastDevice castDevice, String namespace,
String message) {
Log.d("RedditTV", "onMessageReceived: " + message);
}
}
同时收听媒体和YouTube频道
Cast.CastApi.setMessageReceivedCallbacks(mApiClient,
mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
Cast.CastApi.setMessageReceivedCallbacks(mApiClient,
youtubeChannel.getNamespace(),
youtubeChannel);
发送信息以启动视频
String message = String.format(locale,"{\"type\":\"flingVideo\", \"data\":{\"videoId\":\""+redditPost.getYoutubeId()+"\" ,\"currentTime\":%.2f}}",time) ;
Log.w("RedditTV", "Chromecast message to "+ youtubeChannel.getNamespace() + " :"+message);
try {
Cast.CastApi.sendMessage(mApiClient, youtubeChannel.getNamespace(), message)
.setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (!result.isSuccess()) {
Log.e("RedditTV", "Sending message failed");
}
}
});
} catch (Exception e) {
Log.e("RedditTV", "Exception while sending message", e);
}
输出显示发送的实际消息(我也尝试将currentTime设置为0)
Chromecast message to urn:x-cast:com.google.youtube.mdx :{"type":"flingVideo", "data":{"videoId":"4Bn2SEHsyNY" ,"currentTime":1420065958051.00}}
邮件已成功发送,但chromecast端没有任何操作。
我也没有任何好的调试方法。