Can one use CastRemoteDisplay.API and Cast.API on

2019-09-16 01:51发布

问题:

I am developing an Android app with CastRemoteDisplay (Cast SDK v2). When another app starts casting, I want to ensure my app stops casting, so I create my CastOptionsBuilder with the following listener:

Cast.Listener listener = new Cast.Listener() {
    @Override
    public void onApplicationMetadataChanged(ApplicationMetadata metadata) {
        String backdropId = "E8C28D3C"; // id of the Cast backdrop app
        if (!(metadata == null
            || metadata.getApplicationId().equals(backdropId)
            || metadata.getApplicationId().equals(MY_APP_ID)) {
            mMediaRouter.unselect(MediaRouter.UNSELECT_REASON_STOPPED);
        }
    }
};

Then setup the GoogleApiClient with:

GoogleApiClient client = (new GoogleApiClient.Builder(this, callbacks, connectFailListener))
                .addApi(CastRemoteDisplay.API, castRemoteDisplayOptionsBuilder.build())
                .addApi(Cast.API, castOptionsBuilder.build())
                .build();

My question: is it permitted to use both CastRemoteDisplay.API and Cast.API on the same GoogleApiClient?