Domanda

I'm trying to create a simple app which streams a video on Chromecast, using the Cast companion library.

What I'm doing is pretty straightforward. I have an activity with the following code:

    private VideoCastManager mVideoCastManager;


    @Override
    protected void onCreate(Bundle savedInstanceState)
    { 
        mVideoCastManager = CastHelper.getVideoCastManager(this);
    }

And a class called CastHelper with a single method:

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

When I launch the app, I have the media button in the actionbar, and I'm able to selected a device. However, I have an error:

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

Actually the problem is on that block:

 if (null == mApiClient || null == mRemoteMediaPlayer ||
                null == mRemoteMediaPlayer.getMediaStatus()) {
            LOGD(TAG, "mApiClient or mRemoteMediaPlayer is null, so will not proceed");
            return;
 }

The RemoteMediaPlayer instance is fine, but the getMediaStatus method returns null. Notice that I'm not even loading a media yet.

What am I doing wrong?

EDIT As pointed out by Ali Naddaf, maybe this code has nothing wrong, but when I add a VideoCastConsumerImpl the onApplicationConnected is never called, so I was thinking it might be the reason.

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);
È stato utile?

Soluzione

Change mVideoCastManager.addBaseCastConsumer(mCastConsumer); to mVideoCastManager.addVideoCastConsumer(mCastConsumer); and see if that helps.

Altri suggerimenti

What makes you think something is wrong? If you haven't loaded any media yet, then the media status is reasonable to be null and the method that uses the above escape route is all about updating the status of media for various things and at that point, it exits that method since there is practically nothing to do. So are you seeing an issue with that, or maybe I misunderstood the question?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top