我正在尝试使用Cast随播库创建一个在Chromecast上流式传输视频的简单应用。
我所做的非常简单。 我有一个包含以下代码的活动:
private VideoCastManager mVideoCastManager;
@Override
protected void onCreate(Bundle savedInstanceState)
{
mVideoCastManager = CastHelper.getVideoCastManager(this);
}
使用单一方法调用CastHelper
的类:
private static final String APPLICATION_ID = CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
private static VideoCastManager mCastMgr;
public static VideoCastManager getVideoCastManager(Context ctx)
{
if (mCastMgr == null)
{
mCastMgr = VideoCastManager.initialize(ctx, APPLICATION_ID, null, null);
mCastMgr.enableFeatures(VideoCastManager.FEATURE_NOTIFICATION
| VideoCastManager.FEATURE_DEBUGGING);
}
mCastMgr.setContext(ctx);
return mCastMgr;
}
当我启动应用程序时,操作栏中有媒体按钮,我可以选择设备。但是,我有一个错误:
03-26 19:18:47.890: D/ccl_VideoCastManager(9874): Registering MediaChannel namespace
03-26 19:18:47.900: D/ccl_VideoCastManager(9874): onApplicationStatusChanged() reached: Ready To Cast
03-26 19:18:50.203: D/ccl_VideoCastManager(9874): RemoteMediaPlayer::onStatusUpdated() is reached
03-26 19:18:50.203: D/ccl_VideoCastManager(9874): onRemoteMediaPlayerStatusUpdated() reached
03-26 19:18:50.203: D/ccl_VideoCastManager(9874): mApiClient or mRemoteMediaPlayer is null, so will not proceed
实际上问题出在那个区块上:
if (null == mApiClient || null == mRemoteMediaPlayer ||
null == mRemoteMediaPlayer.getMediaStatus()) {
LOGD(TAG, "mApiClient or mRemoteMediaPlayer is null, so will not proceed");
return;
}
RemoteMediaPlayer实例很好,但getMediaStatus
方法返回null。请注意,我甚至没有加载媒体。
我做错了什么?
修改
正如Ali Naddaf指出的那样,也许这段代码没有错,但是当我添加VideoCastConsumerImpl
时,onApplicationConnected
从未被调用过,所以我认为这可能就是原因。
IVideoCastConsumer mCastConsumer = new VideoCastConsumerImpl()
{
@Override
public void onConnected()
{
super.onConnected();
}
@Override
public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched)
{
super.onApplicationConnected(appMetadata, sessionId, wasLaunched);
//Trying to load a media here, but never called
}
};
mVideoCastManager.addBaseCastConsumer(mCastConsumer);
答案 0 :(得分:1)
是什么让你觉得有些不对劲?如果你还没有加载任何媒体,那么媒体状态合理地为null,使用上述转义路由的方法就是为了更新各种事物的媒体状态,并且在那时它退出该方法因为实际上没什么可做的。那么你是否看到了这个问题,或者我误解了这个问题?
答案 1 :(得分:1)
将mVideoCastManager.addBaseCastConsumer(mCastConsumer);
更改为mVideoCastManager.addVideoCastConsumer(mCastConsumer);
,看看是否有帮助。