gpt4 book ai didi

android - RemoteMediaPlayer 媒体状态为空与 Cast 配套库

转载 作者:行者123 更新时间:2023-11-29 00:21:37 30 4
gpt4 key购买 nike

我正在尝试创建一个简单的应用,使用 Cast 配套库在 Chromecast 上流式传输视频。

我正在做的事情非常简单。我有一个使用以下代码的 Activity :

    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

实际上问题出在那个 block 上:

 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);

最佳答案

mVideoCastManager.addBaseCastConsumer(mCastConsumer); 更改为 mVideoCastManager.addVideoCastConsumer(mCastConsumer); 看看是否有帮助。

关于android - RemoteMediaPlayer 媒体状态为空与 Cast 配套库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669963/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com