尝试从Android应用将媒体投射到Chromecast的默认媒体接收器,但它根本不投射。以下是用于查找路径的代码段:
MediaRouteSelector selector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent
.categoryForRemotePlayback(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID))
.build();
然后,它将在WiFi中显示Chromecast设备,并在选择设备时运行以下代码:
MediaRouter.RouteInfo route = adapter.getItem(position).routeInfo;
// select the route for usage
route.select();
// send the play control request with the video uri
route.sendControlRequest(
new Intent(MediaControlIntent.ACTION_PLAY)
.setDataAndType(videoUri, "video/mp4")
.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK),
new MediaRouter.ControlRequestCallback() {
@Override
public void onError(String error, Bundle data) {
super.onError(error, data);
}
@Override
public void onResult(Bundle data) {
super.onResult(data);
}
}
);
无法将媒体投射到设备上。有什么建议吗?
答案 0 :(得分:1)
您似乎没有使用Cast SDK,而是使用Media Route Provider。我没有看到任何会话正在建立;您可能希望查看与Android SDK一起分发的democastplayer示例代码(在SDK文件夹下,转到extras / google / google_play_service / samples / cast / democastplayer)。在该示例中,请查看MrpCastPlayerActivity类。