com.google.android.gms.cast.CastMediaControlIntent Java Examples

The following examples show how to use com.google.android.gms.cast.CastMediaControlIntent. 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: CastOptionsProvider.java    From vinyl-cast with MIT License 7 votes vote down vote up
@Override
public CastOptions getCastOptions(Context appContext) {

    List<String> buttonActions = new ArrayList<>();
    buttonActions.add(MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK);
    buttonActions.add(MediaIntentReceiver.ACTION_STOP_CASTING);
    // Showing "play/pause" and "stop casting" in the compat view of the notification.
    int[] compatButtonActionsIndices = new int[]{ 0, 1 };
    // Builds a notification with the above actions.
    // Tapping on the notification opens an Activity with class VideoBrowserActivity.
    NotificationOptions notificationOptions = new NotificationOptions.Builder()
            .setActions(buttonActions, compatButtonActionsIndices)
            .setTargetActivityClassName(MainActivity.class.getName())
            .build();

    CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
            .setNotificationOptions(notificationOptions)
            .build();

    CastOptions castOptions = new CastOptions.Builder()
            .setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
            .setCastMediaOptions(mediaOptions)
            .build();
    return castOptions;
}
 
Example #2
Source File: BaseCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * ********************************************************************
 */

protected BaseCastManager(Context context, String applicationId) {
  CastUtils.LOGD(TAG, "BaseCastManager is instantiated");
  mContext = context;
  mHandler = new Handler(Looper.getMainLooper());
  mApplicationId = applicationId;
  CastUtils.saveStringToPreference(mContext, PREFS_KEY_APPLICATION_ID, applicationId);

  CastUtils.LOGD(TAG, "Application ID is: " + mApplicationId);
  mMediaRouter = MediaRouter.getInstance(context);
  mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(CastMediaControlIntent
      .categoryForCast(mApplicationId)).build();

  mMediaRouterCallback = new CastMediaRouterCallback(this, context);
  mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
}
 
Example #3
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Send a start session intent.
 *
 * @param relaunch Whether we should relaunch the cast application.
 * @param resultBundleHandler BundleHandler to handle reply.
 */
private void startSession(boolean relaunch, String sessionId,
        ResultBundleHandler resultBundleHandler) {
    Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);

    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS, true);
    intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
            mSessionStatusUpdateIntent);
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID, getCastReceiverId());
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION, relaunch);
    if (sessionId != null) intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);

    addIntentExtraForDebugLogging(intent);
    sendIntentToRoute(intent, resultBundleHandler);
}
 
Example #4
Source File: CastContextImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
public CastContextImpl(IObjectWrapper context, CastOptions options, IMediaRouter router, Map<String, IBinder> sessionProviders) throws RemoteException {
    this.context = (Context) ObjectWrapper.unwrap(context);
    this.options = options;
    this.router = router;
    for (Map.Entry<String, IBinder> entry : sessionProviders.entrySet()) {
        this.sessionProviders.put(entry.getKey(), ISessionProvider.Stub.asInterface(entry.getValue()));
    }

    String receiverApplicationId = options.getReceiverApplicationId();
    String defaultCategory = CastMediaControlIntent.categoryForCast(receiverApplicationId);

    this.defaultSessionProvider = this.sessionProviders.get(defaultCategory);

    // TODO: This should incorporate passed options
    this.mergedSelector = new MediaRouteSelector.Builder()
        .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
        .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
        .addControlCategory(defaultCategory)
        .build();
}
 
Example #5
Source File: CastMediaRouteProvider.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onDiscoveryRequestChanged(MediaRouteDiscoveryRequest request) {
    if (android.os.Build.VERSION.SDK_INT < 16) {
        return;
    }

    if (request != null && request.isValid() && request.isActiveScan()) {
        if (request.getSelector() != null) {
            for (String category : request.getSelector().getControlCategories()) {
                if (CastMediaControlIntent.isCategoryForCast(category)) {
                    this.customCategories.add(category);
                }
            }
        }
        if (this.state == State.NOT_DISCOVERING) {
            mNsdManager.discoverServices("_googlecast._tcp.", NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
            this.state = State.DISCOVERY_REQUESTED;
        }
    } else {
        if (this.state == State.DISCOVERING) {
            mNsdManager.stopServiceDiscovery(mDiscoveryListener);
            this.state = State.DISCOVERY_STOP_REQUESTED;
        }
    }
}
 
Example #6
Source File: Utils.java    From KinoCast with MIT License 6 votes vote down vote up
public static VideoCastManager initializeCastManager(Context context) {
    CastConfiguration.Builder builder = new CastConfiguration.Builder(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
            .enableAutoReconnect()
            .enableCaptionManagement()
            .enableWifiReconnection();

    if(BuildConfig.DEBUG){
        builder.enableDebug();
    }

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    if(preferences.getBoolean("chromecast_lock_screen", true)){
        builder.enableLockScreen();
    }

    if(preferences.getBoolean("chromecast_notification", true)){
        builder.enableNotification()
                .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true)
                .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true);
    }

    return VideoCastManager.initialize(context, builder.build());
}
 
Example #7
Source File: DefaultMediaRouteController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Send a start session intent.
 *
 * @param relaunch Whether we should relaunch the cast application.
 * @param resultBundleHandler BundleHandler to handle reply.
 */
private void startSession(boolean relaunch, String sessionId,
        ResultBundleHandler resultBundleHandler) {
    Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);

    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS, true);
    intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
            mSessionStatusUpdateIntent);
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID, getCastReceiverId());
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION, relaunch);
    if (sessionId != null) intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);

    addIntentExtraForDebugLogging(intent);
    sendIntentToRoute(intent, resultBundleHandler);
}
 
Example #8
Source File: BaseCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/************************************************************************/

    protected BaseCastManager(Context context, String applicationId) {
        CCL_VERSION = context.getString(R.string.ccl_version);
        LOGD(TAG, "BaseCastManager is instantiated");
        mContext = context;
        mHandler = new Handler(Looper.getMainLooper());
        mApplicationId = applicationId;
        Utils.saveStringToPreference(mContext, PREFS_KEY_APPLICATION_ID, applicationId);

        LOGD(TAG, "Application ID is: " + mApplicationId);
        mMediaRouter = MediaRouter.getInstance(context);
        mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
                CastMediaControlIntent.categoryForCast(mApplicationId)).build();

        mMediaRouterCallback = new CastMediaRouterCallback(this, context);
        mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
                MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
    }
 
Example #9
Source File: DefaultMediaRouteController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Send a start session intent.
 *
 * @param relaunch Whether we should relaunch the cast application.
 * @param resultBundleHandler BundleHandler to handle reply.
 */
private void startSession(boolean relaunch, String sessionId,
        ResultBundleHandler resultBundleHandler) {
    Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);

    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS, true);
    intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
            mSessionStatusUpdateIntent);
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID, getCastReceiverId());
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION, relaunch);
    if (sessionId != null) intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);

    addIntentExtraForDebugLogging(intent);
    sendIntentToRoute(intent, resultBundleHandler);
}
 
Example #10
Source File: MediaSource.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link MediaRouteSelector} to use for Cast device filtering for this
 * particular media source or null if the application id is invalid.
 *
 * @return an initialized route selector or null.
 */
public MediaRouteSelector buildRouteSelector() {
    try {
        return new MediaRouteSelector.Builder()
                .addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId))
                .build();
    } catch (IllegalArgumentException e) {
        return null;
    }
}
 
Example #11
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void initMediaRouter() {
    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance( getApplicationContext() );
    mMediaRouteSelector = new MediaRouteSelector.Builder()
            .addControlCategory( CastMediaControlIntent.categoryForCast( getString( R.string.app_id ) ) )
            .build();
    mMediaRouterCallback = new MediaRouterCallback();
}
 
Example #12
Source File: CastOptionsProvider.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public CastOptions getCastOptions(Context context) {
    final NotificationOptions notificationOptions = new NotificationOptions.Builder()
            .setTargetActivityClassName(ExpandedControlsActivity.class.getName())
            .build();
    final CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
            .setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
            .setImagePicker(new ImagePickerImpl())
            .setNotificationOptions(notificationOptions)
            .build();
    return new CastOptions.Builder()
            .setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
            .setCastMediaOptions(mediaOptions)
            .build();
}
 
Example #13
Source File: MediaSource.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link MediaRouteSelector} to use for Cast device filtering for this
 * particular media source or null if the application id is invalid.
 *
 * @return an initialized route selector or null.
 */
public MediaRouteSelector buildRouteSelector() {
    try {
        return new MediaRouteSelector.Builder()
                .addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId))
                .build();
    } catch (IllegalArgumentException e) {
        return null;
    }
}
 
Example #14
Source File: AbstractMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected void updateState(int state) {
    Log.d(TAG, "updateState oldState: %s player state: %s", mRemotePlayerState, state);

    PlayerState oldState = mRemotePlayerState;
    setPlayerStateForMediaItemState(state);

    Log.d(TAG, "updateState newState: %s", mRemotePlayerState);

    if (oldState != mRemotePlayerState) {
        setDisplayedPlayerState(mRemotePlayerState);

        switch (mRemotePlayerState) {
            case PLAYING:
                onCasting();
                break;
            case PAUSED:
                onCasting();
                break;
            case FINISHED:
                release();
                break;
            case INVALIDATED:
                clearItemState();
                break;
            case ERROR:
                sendErrorToListeners(CastMediaControlIntent.ERROR_CODE_REQUEST_FAILED);
                release();
                break;
            default:
                break;
        }
    }
}
 
Example #15
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected void updateState(int state) {
    Log.d(TAG, "updateState oldState: %s player state: %s", mRemotePlayerState, state);

    PlayerState oldState = mRemotePlayerState;
    setPlayerStateForMediaItemState(state);

    Log.d(TAG, "updateState newState: %s", mRemotePlayerState);

    if (oldState != mRemotePlayerState) {
        setDisplayedPlayerState(mRemotePlayerState);

        switch (mRemotePlayerState) {
            case PLAYING:
                onCasting();
                break;
            case PAUSED:
                onCasting();
                break;
            case FINISHED:
                release();
                break;
            case INVALIDATED:
                clearItemState();
                break;
            case ERROR:
                sendErrorToListeners(CastMediaControlIntent.ERROR_CODE_REQUEST_FAILED);
                release();
                break;
            default:
                break;
        }
    }
}
 
Example #16
Source File: AbstractMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
protected void updateState(int state) {
    Log.d(TAG, "updateState oldState: %s player state: %s", mRemotePlayerState, state);

    PlayerState oldState = mRemotePlayerState;
    setPlayerStateForMediaItemState(state);

    Log.d(TAG, "updateState newState: %s", mRemotePlayerState);

    if (oldState != mRemotePlayerState) {
        setDisplayedPlayerState(mRemotePlayerState);

        switch (mRemotePlayerState) {
            case PLAYING:
                onCasting();
                break;
            case PAUSED:
                onCasting();
                break;
            case FINISHED:
                release();
                break;
            case INVALIDATED:
                clearItemState();
                break;
            case ERROR:
                sendErrorToListeners(CastMediaControlIntent.ERROR_CODE_REQUEST_FAILED);
                release();
                break;
            default:
                break;
        }
    }
}
 
Example #17
Source File: MediaSource.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link MediaRouteSelector} to use for Cast device filtering for this
 * particular media source or null if the application id is invalid.
 *
 * @return an initialized route selector or null.
 */
public MediaRouteSelector buildRouteSelector() {
    try {
        return new MediaRouteSelector.Builder()
                .addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId))
                .build();
    } catch (IllegalArgumentException e) {
        return null;
    }
}
 
Example #18
Source File: GoogleCastOptionsProvider.java    From react-native-google-cast with MIT License 5 votes vote down vote up
@Override
public CastOptions getCastOptions(Context context) {
  NotificationOptions notificationOptions =
      new NotificationOptions.Builder()
          .setActions(
              Arrays.asList(MediaIntentReceiver.ACTION_SKIP_NEXT,
                            MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK,
                            MediaIntentReceiver.ACTION_STOP_CASTING),
              new int[] {1, 2})
          .setTargetActivityClassName(
              GoogleCastExpandedControlsActivity.class.getName())
          .build();

  CastMediaOptions mediaOptions =
      new CastMediaOptions.Builder()
          .setImagePicker(new ImagePickerImpl())
          .setNotificationOptions(notificationOptions)
          .setExpandedControllerActivityClassName(
              GoogleCastExpandedControlsActivity.class.getName())
          .build();

  return new CastOptions.Builder()
      .setReceiverApplicationId(
          CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
      .setCastMediaOptions(mediaOptions)
      .build();
}
 
Example #19
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public MediaRouteSelector buildMediaRouteSelector() {
    return new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForRemotePlayback(getCastReceiverId())).build();
}
 
Example #20
Source File: RemoteMediaPlayerController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onError(int error, String errorMessage) {
    if (error == CastMediaControlIntent.ERROR_CODE_SESSION_START_FAILED) {
        showMessageToast(errorMessage);
    }
}
 
Example #21
Source File: MainApplication.java    From UTubeTV with The Unlicense 4 votes vote down vote up
@Override
public void onCreate() {
  super.onCreate();
  sApplicationID = CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID; // "6142AE0B"; // "5A3D7A5C";
  CastUtils.saveFloatToPreference(getApplicationContext(), VideoCastManager.PREFS_KEY_VOLUME_INCREMENT, (float) VOLUME_INCREMENT);
}
 
Example #22
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 4 votes vote down vote up
protected String getCastReceiverId() {
    return CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
}
 
Example #23
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 4 votes vote down vote up
@RemovableInRelease
private void addIntentExtraForDebugLogging(Intent intent) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        intent.putExtra(CastMediaControlIntent.EXTRA_DEBUG_LOGGING_ENABLED, true);
    }
}
 
Example #24
Source File: ExpandedControllerActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onError(int error, String message) {
    if (error == CastMediaControlIntent.ERROR_CODE_SESSION_START_FAILED) finish();
}
 
Example #25
Source File: RemoteMediaPlayerController.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onError(int error, String errorMessage) {
    if (error == CastMediaControlIntent.ERROR_CODE_SESSION_START_FAILED) {
        showMessageToast(errorMessage);
    }
}
 
Example #26
Source File: GoogleCompat.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
public static String getCastControlCategory() {
    return CastMediaControlIntent.categoryForCast(EnvironmentVariables.CAST_APPLICATION_ID);
}
 
Example #27
Source File: RemoteMediaPlayerController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onError(int error, String errorMessage) {
    if (error == CastMediaControlIntent.ERROR_CODE_SESSION_START_FAILED) {
        showMessageToast(errorMessage);
    }
}
 
Example #28
Source File: ExpandedControllerActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onError(int error, String message) {
    if (error == CastMediaControlIntent.ERROR_CODE_SESSION_START_FAILED) finish();
}
 
Example #29
Source File: DefaultMediaRouteController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@RemovableInRelease
private void addIntentExtraForDebugLogging(Intent intent) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        intent.putExtra(CastMediaControlIntent.EXTRA_DEBUG_LOGGING_ENABLED, true);
    }
}
 
Example #30
Source File: DefaultMediaRouteController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public MediaRouteSelector buildMediaRouteSelector() {
    return new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForRemotePlayback(getCastReceiverId())).build();
}