Running a custom chrome receiver is sometimes not enough

I have a custom Chromecast receiver that I launch from an Android app when a user selects their Chromecast device from the Cast button. I find that I often get a timeout in the original connection, but the second time it works fine. Is the problem, most likely my web server is not responding fast enough or are there other factors that can cause a timeout?

I get CastStatusCodes.TIMEOUT in onApplicationConnectionFailed ().

My code to run (EDITED includes launching the application)

Builder builder = new GoogleApiClient.Builder(mContext);
builder.addApi(Cast.API, apiOptionsBuilder.build());
builder.addConnectionCallbacks(this);
builder.addOnConnectionFailedListener(this);
mApiClient = builder.build();

if (mApiClient == null) return;
mApiClient.connect();

...

Cast.CastApi.launchApplication(mApiClient, mApplicationId)
 .setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {

    @Override
    public void onResult(ApplicationConnectionResult result) {
        if (result.getStatus().isSuccess()) {
            onApplicationConnected(
                result.getApplicationMetadata(),
                result.getApplicationStatus(),
                result.getSessionId(),
                result.getWasLaunched());
        } else {
                onApplicationConnectionFailed(result.getStatus().getStatusCode());
        }
    }
});   
+3
source share
1 answer

, , , , - onApplicationConnectionFailed, , , . , - ..

0

All Articles