@Override
        public void onResult(ApplicationConnectionResult result) {

          Status status = result.getStatus();

          if (status.isSuccess()) {
            try {
              ApplicationMetadata metadata = result.getApplicationMetadata();
              ChromecastSession.this.sessionId = result.getSessionId();
              ChromecastSession.this.displayName = metadata.getName();
              ChromecastSession.this.appImages = metadata.getImages();

              ChromecastSession.this.joinSessionCallback.onSuccess(ChromecastSession.this);
              connectRemoteMediaPlayer();
              ChromecastSession.this.isConnected = true;
            } catch (IllegalStateException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
          } else {
            ChromecastSession.this.joinSessionCallback.onError(status.toString());
            ChromecastSession.this.isConnected = false;
          }
        }
Exemplo n.º 2
0
  @Override
  public CastSessionInfo getSessionInfo() {
    if (isApiClientInvalid()) return null;

    CastSessionInfo.VolumeInfo.Builder volumeBuilder =
        new CastSessionInfo.VolumeInfo.Builder()
            .setLevel(Cast.CastApi.getVolume(mApiClient))
            .setMuted(Cast.CastApi.isMute(mApiClient));

    CastSessionInfo.ReceiverInfo.Builder receiverBuilder =
        new CastSessionInfo.ReceiverInfo.Builder()
            .setLabel(mCastDevice.getDeviceId())
            .setFriendlyName(mCastDevice.getFriendlyName())
            .setVolume(volumeBuilder.build())
            .setIsActiveInput(Cast.CastApi.getActiveInputState(mApiClient))
            .setDisplayStatus(null)
            .setReceiverType("cast")
            .addCapabilities(getCapabilities(mCastDevice));

    CastSessionInfo.Builder sessionInfoBuilder =
        new CastSessionInfo.Builder()
            .setSessionId(mSessionId)
            .setStatusText(mApplicationStatus)
            .setReceiver(receiverBuilder.build())
            .setStatus("connected")
            .setTransportId("web-4")
            .addNamespaces(mNamespaces);

    if (mApplicationMetadata != null) {
      sessionInfoBuilder
          .setAppId(mApplicationMetadata.getApplicationId())
          .setDisplayName(mApplicationMetadata.getName());
    } else {
      sessionInfoBuilder
          .setAppId(mSource.getApplicationId())
          .setDisplayName(mCastDevice.getFriendlyName());
    }

    return sessionInfoBuilder.build();
  }
Exemplo n.º 3
0
  private void updateNamespaces() {
    if (mApplicationMetadata == null) return;

    List<String> newNamespaces = mApplicationMetadata.getSupportedNamespaces();

    Set<String> toRemove = new HashSet<String>(mNamespaces);
    toRemove.removeAll(newNamespaces);
    for (String namespaceToRemove : toRemove) unregisterNamespace(namespaceToRemove);

    for (String newNamespace : newNamespaces) {
      if (!mNamespaces.contains(newNamespace)) addNamespace(newNamespace);
    }
  }
Exemplo n.º 4
0
 static void a(ApplicationMetadata applicationMetadata, Parcel parcel, int n) {
   int n2 = b.D(parcel);
   b.c(parcel, 1, applicationMetadata.getVersionCode());
   b.a(parcel, 2, applicationMetadata.getApplicationId(), false);
   b.a(parcel, 3, applicationMetadata.getName(), false);
   b.c(parcel, 4, applicationMetadata.getImages(), false);
   b.b(parcel, 5, applicationMetadata.EB, false);
   b.a(parcel, 6, applicationMetadata.getSenderAppIdentifier(), false);
   b.a(parcel, 7, applicationMetadata.fu(), n, false);
   b.H(parcel, n2);
 }
Exemplo n.º 5
0
  private void addNamespace(String namespace) {
    assert !mNamespaces.contains(namespace);

    if (isApiClientInvalid()) return;

    // If application metadata is null, register the callback anyway.
    if (mApplicationMetadata != null && !mApplicationMetadata.isNamespaceSupported(namespace)) {
      return;
    }

    try {
      Cast.CastApi.setMessageReceivedCallbacks(mApiClient, namespace, mMessageChannel);
      mNamespaces.add(namespace);
    } catch (IOException e) {
      Log.e(TAG, "Failed to register namespace listener for %s", namespace, e);
    }
  }