Java Code Examples for com.google.android.gms.cast.CastDevice#getFromBundle()

The following examples show how to use com.google.android.gms.cast.CastDevice#getFromBundle() . 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: BaseCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
private void reconnectSessionIfPossibleInternal(RouteInfo theRoute) {
    if (isConnected()) {
        return;
    }
    String sessionId = Utils.getStringFromPreference(mContext, PREFS_KEY_SESSION_ID);
    String routeId = Utils.getStringFromPreference(mContext, PREFS_KEY_ROUTE_ID);
    LOGD(TAG, "reconnectSessionIfPossible() Retrieved from preferences: " + "sessionId="
            + sessionId + ", routeId=" + routeId);
    if (null == sessionId || null == routeId) {
        return;
    }
    mReconnectionStatus = ReconnectionStatus.IN_PROGRESS;
    CastDevice device = CastDevice.getFromBundle(theRoute.getExtras());

    if (null != device) {
        LOGD(TAG, "trying to acquire Cast Client for " + device);
        onDeviceSelected(device);
    }
}
 
Example 2
Source File: CastMediaRouterCallback.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public void onRouteAdded(MediaRouter router, RouteInfo route) {
    super.onRouteAdded(router, route);
    if (!router.getDefaultRoute().equals(route)) {
        if (++mRouteCount == 1) {
            BaseCastManager.getCastManager().onCastAvailabilityChanged(true);
        }
        selectDeviceInterface.onCastDeviceDetected(route);
    }
    if (BaseCastManager.getCastManager().getReconnectionStatus() == ReconnectionStatus.STARTED) {
        String routeId = Utils.getStringFromPreference(mContext,
                BaseCastManager.PREFS_KEY_ROUTE_ID);
        if (route.getId().equals(routeId)) {
            // we found the route, so lets go with that
            LOGD(TAG, "onRouteAdded: Attempting to recover a session with info=" + route);
            BaseCastManager.getCastManager().setReconnectionStatus(
                    ReconnectionStatus.IN_PROGRESS);

            CastDevice device = CastDevice.getFromBundle(route.getExtras());
            LOGD(TAG, "onRouteAdded: Attempting to recover a session with device: "
                    + device.getFriendlyName());
            selectDeviceInterface.onDeviceSelected(device);
        }
    }
}
 
Example 3
Source File: CastDeviceControllerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
public CastDeviceControllerImpl(Context context, String packageName, Bundle extras) {
    this.context = context;
    this.packageName = packageName;

    extras.setClassLoader(BinderWrapper.class.getClassLoader());
    this.castDevice = CastDevice.getFromBundle(extras);
    this.notificationEnabled = extras.getBoolean("com.google.android.gms.cast.EXTRA_CAST_FRAMEWORK_NOTIFICATION_ENABLED");
    this.castFlags = extras.getLong("com.google.android.gms.cast.EXTRA_CAST_FLAGS");
    BinderWrapper listenerWrapper = (BinderWrapper)extras.get("listener");
    if (listenerWrapper != null) {
        this.listener = ICastDeviceControllerListener.Stub.asInterface(listenerWrapper.binder);
    }

    this.chromecast = new ChromeCast(this.castDevice.getAddress());
    this.chromecast.registerListener(this);
    this.chromecast.registerRawMessageListener(this);
    this.chromecast.registerConnectionListener(this);
}
 
Example 4
Source File: BaseCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private void reconnectSessionIfPossibleInternal(RouteInfo theRoute) {
  if (isConnected()) {
    return;
  }
  String sessionId = CastUtils.getStringFromPreference(mContext, PREFS_KEY_SESSION_ID);
  String routeId = CastUtils.getStringFromPreference(mContext, PREFS_KEY_ROUTE_ID);
  CastUtils.LOGD(TAG, "reconnectSessionIfPossible() Retrieved from preferences: " + "sessionId=" + sessionId + ", routeId=" + routeId);
  if (null == sessionId || null == routeId) {
    return;
  }
  mReconnectionStatus = ReconnectionStatus.IN_PROGRESS;
  CastDevice device = CastDevice.getFromBundle(theRoute.getExtras());

  if (null != device) {
    CastUtils.LOGD(TAG, "trying to acquire Cast Client for " + device);
    onDeviceSelected(device);
  }
}
 
Example 5
Source File: CastMediaRouterCallback.java    From UTubeTV with The Unlicense 6 votes vote down vote up
@Override
public void onRouteAdded(MediaRouter router, RouteInfo route) {
  super.onRouteAdded(router, route);
  if (!router.getDefaultRoute().equals(route)) {
    selectDeviceInterface.onCastDeviceDetected(route);
  }
  if (BaseCastManager.getCastManager().getReconnectionStatus() == ReconnectionStatus.STARTED) {
    String routeId = CastUtils.getStringFromPreference(mContext, BaseCastManager.PREFS_KEY_ROUTE_ID);
    if (route.getId().equals(routeId)) {
      // we found the route, so lets go with that
      CastUtils.LOGD(TAG, "onRouteAdded: Attempting to recover a session with info=" + route);
      BaseCastManager.getCastManager().setReconnectionStatus(ReconnectionStatus.IN_PROGRESS);

      CastDevice device = CastDevice.getFromBundle(route.getExtras());
      CastUtils.LOGD(TAG, "onRouteAdded: Attempting to recover a session with device: " + device.getFriendlyName());
      selectDeviceInterface.onDeviceSelected(device);
    }
  }
}
 
Example 6
Source File: MediaSink.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @param route The route information provided by Android.
 * @return A new MediaSink instance corresponding to the specified {@link RouteInfo}.
 */
public static MediaSink fromRoute(MediaRouter.RouteInfo route) {
    return new MediaSink(
        route.getId(),
        route.getName(),
        CastDevice.getFromBundle(route.getExtras()));
}
 
Example 7
Source File: MediaSink.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @param route The route information provided by Android.
 * @return A new MediaSink instance corresponding to the specified {@link RouteInfo}.
 */
public static MediaSink fromRoute(MediaRouter.RouteInfo route) {
    return new MediaSink(
        route.getId(),
        route.getName(),
        CastDevice.getFromBundle(route.getExtras()));
}
 
Example 8
Source File: CastMediaRouterCallback.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
    LOGD(TAG, "onRouteSelected: info=" + info);
    if (BaseCastManager.getCastManager().getReconnectionStatus()
            == BaseCastManager.ReconnectionStatus.FINALIZE) {
        BaseCastManager.getCastManager().setReconnectionStatus(ReconnectionStatus.INACTIVE);
        BaseCastManager.getCastManager().cancelReconnectionTask();
        return;
    }
    Utils.saveStringToPreference(mContext, BaseCastManager.PREFS_KEY_ROUTE_ID, info.getId());
    CastDevice device = CastDevice.getFromBundle(info.getExtras());
    selectDeviceInterface.onDeviceSelected(device);
    LOGD(TAG, "onResult: mSelectedDevice=" + device.getFriendlyName());
}
 
Example 9
Source File: MediaSink.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param route The route information provided by Android.
 * @return A new MediaSink instance corresponding to the specified {@link RouteInfo}.
 */
public static MediaSink fromRoute(MediaRouter.RouteInfo route) {
    return new MediaSink(
        route.getId(),
        route.getName(),
        CastDevice.getFromBundle(route.getExtras()));
}
 
Example 10
Source File: GoogleCompat.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public static RemoteController getController(DownloadService downloadService, MediaRouter.RouteInfo info) {
    CastDevice device = CastDevice.getFromBundle(info.getExtras());
    if(device != null) {
        return new ChromeCastController(downloadService, device);
    } else {
        return null;
    }
}
 
Example 11
Source File: MediaRouterCallbackImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteSelected(String routeId, Bundle extras) throws RemoteException {
    CastDevice castDevice = CastDevice.getFromBundle(extras);

    SessionImpl session = (SessionImpl) ObjectWrapper.unwrap(this.castContext.defaultSessionProvider.getSession(null));
    Bundle routeInfoExtras = this.castContext.getRouter().getRouteInfoExtrasById(routeId);
    if (routeInfoExtras != null) {
        session.start(this.castContext, castDevice, routeId, routeInfoExtras);
    }
}
 
Example 12
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
    initCastClientListener();
    initRemoteMediaPlayer();

    mSelectedDevice = CastDevice.getFromBundle( info.getExtras() );

    launchReceiver();
}
 
Example 13
Source File: CastMediaRouterCallback.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
  CastUtils.LOGD(TAG, "onRouteSelected: info=" + info);
  if (BaseCastManager.getCastManager()
      .getReconnectionStatus() == BaseCastManager.ReconnectionStatus.FINALIZE) {
    BaseCastManager.getCastManager().setReconnectionStatus(ReconnectionStatus.INACTIVE);
    BaseCastManager.getCastManager().cancelReconnectionTask();
    return;
  }
  CastUtils.saveStringToPreference(mContext, BaseCastManager.PREFS_KEY_ROUTE_ID, info.getId());
  CastDevice device = CastDevice.getFromBundle(info.getExtras());
  selectDeviceInterface.onDeviceSelected(device);
  CastUtils.LOGD(TAG, "onResult: mSelectedDevice=" + device.getFriendlyName());
}