Esempio n. 1
0
  private void setNotificationMetadata(MediaNotificationInfo.Builder builder) {
    MediaMetadata notificationMetadata = new MediaMetadata("", "", "");
    builder.setMetadata(notificationMetadata);

    if (mCastDevice != null) notificationMetadata.setTitle(mCastDevice.getFriendlyName());

    if (mMediaPlayer == null) return;

    com.google.android.gms.cast.MediaInfo info = mMediaPlayer.getMediaInfo();
    if (info == null) return;

    com.google.android.gms.cast.MediaMetadata metadata = info.getMetadata();
    if (metadata == null) return;

    String title = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_TITLE);
    if (title != null) notificationMetadata.setTitle(title);

    String artist = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ARTIST);
    if (artist == null) {
      artist = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_ARTIST);
    }
    if (artist != null) notificationMetadata.setArtist(artist);

    String album = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_TITLE);
    if (album != null) notificationMetadata.setAlbum(album);
  }
Esempio n. 2
0
 /**
  * @param device The {@link CastDevice} queried for it's capabilities.
  * @return The capabilities of the Cast device. TODO(zqzhang): move to a CastUtils class?
  */
 protected static List<String> getCapabilities(CastDevice device) {
   List<String> capabilities = new ArrayList<String>();
   if (device.hasCapability(CastDevice.CAPABILITY_AUDIO_IN)) {
     capabilities.add("audio_in");
   }
   if (device.hasCapability(CastDevice.CAPABILITY_AUDIO_OUT)) {
     capabilities.add("audio_out");
   }
   if (device.hasCapability(CastDevice.CAPABILITY_VIDEO_IN)) {
     capabilities.add("video_in");
   }
   if (device.hasCapability(CastDevice.CAPABILITY_VIDEO_OUT)) {
     capabilities.add("video_out");
   }
   return capabilities;
 }
Esempio n. 3
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();
  }
  public ChromecastSession(
      RouteInfo routeInfo,
      CordovaInterface cordovaInterface,
      ChromecastOnMediaUpdatedListener onMediaUpdatedListener,
      ChromecastOnSessionUpdatedListener onSessionUpdatedListener) {
    this.cordova = cordovaInterface;
    this.onMediaUpdatedListener = onMediaUpdatedListener;
    this.onSessionUpdatedListener = onSessionUpdatedListener;
    this.routeInfo = routeInfo;
    this.device = CastDevice.getFromBundle(this.routeInfo.getExtras());

    this.mRemoteMediaPlayer = new RemoteMediaPlayer();
    this.mRemoteMediaPlayer.setOnMetadataUpdatedListener(this);
    this.mRemoteMediaPlayer.setOnStatusUpdatedListener(this);

    this.chromecastMediaController = new ChromecastMediaController(mRemoteMediaPlayer);
  }
Esempio n. 5
0
 @Override
 public String getSinkId() {
   return mCastDevice.getDeviceId();
 }