Java Code Examples for com.google.android.gms.cast.Cast#CastApi

The following examples show how to use com.google.android.gms.cast.Cast#CastApi . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the custom data channel, if any. It returns <code>true</code> if it succeeds
 * otherwise if it encounters an error or if no connection exists or if no custom data channel
 * exists, then it returns <code>false</code>
 *
 * @return
 */
public boolean removeDataChannel() {
    if (TextUtils.isEmpty(mDataNamespace)) {
        return false;
    }
    try {
        if (null != Cast.CastApi && null != mApiClient) {
            Cast.CastApi.removeMessageReceivedCallbacks(mApiClient, mDataNamespace);
        }
        mDataChannel = null;
        Utils.saveStringToPreference(mContext, PREFS_KEY_CAST_CUSTOM_DATA_NAMESPACE, null);
        return true;
    } catch (Exception e) {
        LOGE(TAG, "Failed to remove namespace: " + mDataNamespace, e);
    }
    return false;

}
 
Example 2
Source File: DataCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * *********** Cast.Listener callbacks *********************************
 */

/*
 * Adds namespaces for data channel(s)
 * @throws NoConnectionException If no connectivity to the device exists
 * @throws TransientNetworkDisconnectionException If framework is still trying to recover from a
 * possibly transient loss of network
 * @throws IOException If an I/O error occurs while performing the request.
 * @throws IllegalStateException Thrown when the controller is not connected to a CastDevice.
 * @throws IllegalArgumentException If namespace is null.
 */
private void attachDataChannels() throws IllegalStateException, IOException, TransientNetworkDisconnectionException, NoConnectionException {
  checkConnectivity();
  if (!mNamespaceList.isEmpty() && null != Cast.CastApi) {
    for (String namespace : mNamespaceList) {
      Cast.CastApi.setMessageReceivedCallbacks(mApiClient, namespace, this);
    }
  }
}
 
Example 3
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Remove the custom data channel, if any. It returns <code>true</code> if it succeeds otherwise
 * if it encounters an error or if no connection exists or if no custom data channel exists,
 * then it returns <code>false</code>
 */
public boolean removeDataChannel() {
  if (TextUtils.isEmpty(mDataNamespace)) {
    return false;
  }
  try {
    if (null != Cast.CastApi && null != mApiClient) {
      Cast.CastApi.removeMessageReceivedCallbacks(mApiClient, mDataNamespace);
    }
    return true;
  } catch (Exception e) {
    CastUtils.LOGE(TAG, "Failed to remove namespace: " + mDataNamespace, e);
  }
  return false;

}
 
Example 4
Source File: DataCastManager.java    From android with Apache License 2.0 5 votes vote down vote up
private void attachDataChannels() throws IllegalStateException, IOException,
        TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    if (!mNamespaceList.isEmpty() && null != Cast.CastApi) {
        for (String namespace : mNamespaceList) {
            Cast.CastApi.setMessageReceivedCallbacks(mApiClient, namespace, this);
        }
    }
}
 
Example 5
Source File: DataCastManager.java    From android with Apache License 2.0 5 votes vote down vote up
private void detachDataChannels() {
    if (!mNamespaceList.isEmpty() && null != Cast.CastApi && null != mApiClient) {
        for (String namespace : mNamespaceList) {
            try {
                Cast.CastApi.removeMessageReceivedCallbacks(mApiClient, namespace);
            } catch (Exception e) {
                LOGE(TAG, "Failed to add namespace: " + namespace, e);
            }
        }
    }
}
 
Example 6
Source File: VideoCastManager.java    From android with Apache License 2.0 5 votes vote down vote up
private void detachMediaChannel() {
    LOGD(TAG, "trying to detach media channel");
    if (null != mRemoteMediaPlayer) {
        if (null != mRemoteMediaPlayer && null != Cast.CastApi) {
            try {
                Cast.CastApi.removeMessageReceivedCallbacks(mApiClient,
                        mRemoteMediaPlayer.getNamespace());
            } catch (Exception e) {
                LOGE(TAG, "Failed to detach media channel", e);
            }
        }
        mRemoteMediaPlayer = null;
    }
}
 
Example 7
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 5 votes vote down vote up
private void detachMediaChannel() {
  CastUtils.LOGD(TAG, "trying to detach media channel");
  if (null != mRemoteMediaPlayer) {
    if (null != mRemoteMediaPlayer && null != Cast.CastApi) {
      try {
        Cast.CastApi.removeMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace());
      } catch (IOException e) {
        CastUtils.LOGE(TAG, "Failed to detach media channel", e);
      }
    }
    mRemoteMediaPlayer = null;
  }
}