android.support.v7.media.MediaRouteSelector Java Examples

The following examples show how to use android.support.v7.media.MediaRouteSelector. 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 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 #2
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 #3
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 #4
Source File: MediaRouteChooserDialogManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected DialogFragment openDialogInternal(FragmentManager fm) {
    if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null;

    Fragment fragment = new Fragment(this);
    MediaRouteSelector selector = mediaSource().buildRouteSelector();
    if (selector == null) return null;

    fragment.setRouteSelector(selector);
    fragment.show(fm, DIALOG_FRAGMENT_TAG);
    fm.executePendingTransactions();

    return fragment;
}
 
Example #5
Source File: MediaRouteControllerDialogManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected DialogFragment openDialogInternal(FragmentManager fm) {
    if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null;

    Fragment fragment = new Fragment(this, mCallback);
    MediaRouteSelector selector = mediaSource().buildRouteSelector();
    if (selector == null) return null;

    androidMediaRouter().addCallback(selector, mCallback);

    fragment.show(fm, DIALOG_FRAGMENT_TAG);
    fm.executePendingTransactions();

    return fragment;
}
 
Example #6
Source File: MediaRouteChooserDialogManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected DialogFragment openDialogInternal(FragmentManager fm) {
    if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null;

    Fragment fragment = new Fragment(this);
    MediaRouteSelector selector = mediaSource().buildRouteSelector();
    if (selector == null) return null;

    fragment.setRouteSelector(selector);
    fragment.show(fm, DIALOG_FRAGMENT_TAG);
    fm.executePendingTransactions();

    return fragment;
}
 
Example #7
Source File: DiscoveryCallback.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public DiscoveryCallback(String sourceUrn, List<MediaSink> knownSinks,
        DiscoveryDelegate delegate, MediaRouteSelector selector) {
    assert delegate != null;
    assert sourceUrn != null && !sourceUrn.isEmpty();

    mSinks.addAll(knownSinks);
    mDiscoveryDelegate = delegate;
    mRouteSelector = selector;

    addSourceUrn(sourceUrn);
}
 
Example #8
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 #9
Source File: MediaRouteManager.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public void buildSelector() {
	MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder();
	if(UserUtil.canJukebox()) {
		builder.addControlCategory(JukeboxRouteProvider.CATEGORY_JUKEBOX_ROUTE);
	}
	if(castAvailable) {
		builder.addControlCategory(GoogleCompat.getCastControlCategory());
	}
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
		builder.addControlCategory(DLNARouteProvider.CATEGORY_DLNA);
	}
	selector = builder.build();
}
 
Example #10
Source File: MediaRouteControllerDialogManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected DialogFragment openDialogInternal(FragmentManager fm) {
    if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null;

    Fragment fragment = new Fragment(this, mCallback);
    MediaRouteSelector selector = mediaSource().buildRouteSelector();
    if (selector == null) return null;

    androidMediaRouter().addCallback(selector, mCallback);

    fragment.show(fm, DIALOG_FRAGMENT_TAG);
    fm.executePendingTransactions();

    return fragment;
}
 
Example #11
Source File: DiscoveryCallback.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public DiscoveryCallback(String sourceUrn, List<MediaSink> knownSinks,
        DiscoveryDelegate delegate, MediaRouteSelector selector) {
    assert delegate != null;
    assert sourceUrn != null && !sourceUrn.isEmpty();

    mSinks.addAll(knownSinks);
    mDiscoveryDelegate = delegate;
    mRouteSelector = selector;

    addSourceUrn(sourceUrn);
}
 
Example #12
Source File: CastMediaRouteProvider.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void startObservingMediaSinks(String sourceId) {
    if (mAndroidMediaRouter == null) return;

    MediaSource source = MediaSource.from(sourceId);
    if (source == null) return;

    MediaRouteSelector routeSelector = source.buildRouteSelector();
    if (routeSelector == null) {
        // If the application invalid, report no devices available.
        onSinksReceived(sourceId, new ArrayList<MediaSink>());
        return;
    }

    String applicationId = source.getApplicationId();
    DiscoveryCallback callback = mDiscoveryCallbacks.get(applicationId);
    if (callback != null) {
        callback.addSourceUrn(sourceId);
        return;
    }

    List<MediaSink> knownSinks = new ArrayList<MediaSink>();
    for (RouteInfo route : mAndroidMediaRouter.getRoutes()) {
        if (route.matchesSelector(routeSelector)) {
            knownSinks.add(MediaSink.fromRoute(route));
        }
    }

    callback = new DiscoveryCallback(sourceId, knownSinks, this, routeSelector);
    mAndroidMediaRouter.addCallback(
            routeSelector,
            callback,
            MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
    mDiscoveryCallbacks.put(applicationId, callback);
}
 
Example #13
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 #14
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 #15
Source File: MediaRouteControllerDialogManager.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected DialogFragment openDialogInternal(FragmentManager fm) {
    if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null;

    MediaRouteControllerDialogFragment fragment = new MediaRouteControllerDialogFragment() {
        final SystemVisibilitySaver mVisibilitySaver = new SystemVisibilitySaver();

        @Override
        public void onStart() {
            mVisibilitySaver.saveSystemVisibility(getActivity());
            super.onStart();
        }

        @Override
        public void onStop() {
            super.onStop();
            mVisibilitySaver.restoreSystemVisibility(getActivity());
        }

        @Override
        public void onDismiss(DialogInterface dialog) {
            delegate().onDialogCancelled();
            androidMediaRouter().removeCallback(mCallback);
            mDialogFragment = null;
            super.onDismiss(dialog);
        }
    };

    MediaRouteSelector selector = mediaSource().buildRouteSelector();
    if (selector == null) return null;

    androidMediaRouter().addCallback(selector, mCallback);

    fragment.show(fm, DIALOG_FRAGMENT_TAG);
    fm.executePendingTransactions();

    return fragment;
}
 
Example #16
Source File: DiscoveryCallback.java    From delion with Apache License 2.0 5 votes vote down vote up
public DiscoveryCallback(String sourceUrn, List<MediaSink> knownSinks,
        DiscoveryDelegate delegate, MediaRouteSelector selector) {
    assert delegate != null;
    assert sourceUrn != null && !sourceUrn.isEmpty();

    mSinks.addAll(knownSinks);
    mDiscoveryDelegate = delegate;
    mRouteSelector = selector;

    addSourceUrn(sourceUrn);
}
 
Example #17
Source File: CastMediaRouteProvider.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void startObservingMediaSinks(String sourceId) {
    if (mAndroidMediaRouter == null) return;

    MediaSource source = MediaSource.from(sourceId);
    if (source == null) return;

    MediaRouteSelector routeSelector = source.buildRouteSelector();
    if (routeSelector == null) {
        // If the application invalid, report no devices available.
        onSinksReceived(sourceId, new ArrayList<MediaSink>());
        return;
    }

    String applicationId = source.getApplicationId();
    DiscoveryCallback callback = mDiscoveryCallbacks.get(applicationId);
    if (callback != null) {
        callback.addSourceUrn(sourceId);
        return;
    }

    List<MediaSink> knownSinks = new ArrayList<MediaSink>();
    for (RouteInfo route : mAndroidMediaRouter.getRoutes()) {
        if (route.matchesSelector(routeSelector)) {
            knownSinks.add(MediaSink.fromRoute(route));
        }
    }

    callback = new DiscoveryCallback(sourceId, knownSinks, this, routeSelector);
    mAndroidMediaRouter.addCallback(
            routeSelector,
            callback,
            MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
    mDiscoveryCallbacks.put(applicationId, callback);
}
 
Example #18
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 #19
Source File: DefaultMediaRouteController.java    From 365browser 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: CastContextImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 4 votes vote down vote up
public MediaRouteSelector getMergedSelector() {
    return this.mergedSelector;
}
 
Example #21
Source File: MediaRouteManager.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
public MediaRouteSelector getSelector() {
	return selector;
}
 
Example #22
Source File: BaseCastManager.java    From UTubeTV with The Unlicense 4 votes vote down vote up
/**
 * Returns the {@link MediaRouteSelector} object.
 */
public final MediaRouteSelector getMediaRouteSelector() {
  return mMediaRouteSelector;
}
 
Example #23
Source File: DownloadService.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
public MediaRouteSelector getRemoteSelector() {
	return mediaRouter.getSelector();
}
 
Example #24
Source File: CastMediaRouteProvider.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void startObservingMediaSinks(String sourceId) {
    if (mAndroidMediaRouter == null) {
        // If the MediaRouter API is not available, report no devices so the page doesn't even
        // try to cast.
        onSinksReceived(sourceId, new ArrayList<MediaSink>());
        return;
    }

    MediaSource source = MediaSource.from(sourceId);
    if (source == null) {
        // If the source is invalid, report no devices available.
        onSinksReceived(sourceId, new ArrayList<MediaSink>());
        return;
    }

    MediaRouteSelector routeSelector = source.buildRouteSelector();
    if (routeSelector == null) {
        // If the application invalid, report no devices available.
        onSinksReceived(sourceId, new ArrayList<MediaSink>());
        return;
    }

    String applicationId = source.getApplicationId();
    DiscoveryCallback callback = mDiscoveryCallbacks.get(applicationId);
    if (callback != null) {
        callback.addSourceUrn(sourceId);
        return;
    }

    List<MediaSink> knownSinks = new ArrayList<MediaSink>();
    for (RouteInfo route : mAndroidMediaRouter.getRoutes()) {
        if (route.matchesSelector(routeSelector)) {
            knownSinks.add(MediaSink.fromRoute(route));
        }
    }

    callback = new DiscoveryCallback(sourceId, knownSinks, this, routeSelector);
    mAndroidMediaRouter.addCallback(
            routeSelector,
            callback,
            MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
    mDiscoveryCallbacks.put(applicationId, callback);
}
 
Example #25
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 #26
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();
}
 
Example #27
Source File: MediaRouteController.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * @return A new MediaRouteSelector filtering the remote playback devices from all the routes.
 */
MediaRouteSelector buildMediaRouteSelector();
 
Example #28
Source File: BaseCastManager.java    From android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the {@link MediaRouteSelector} object.
 *
 * @return
 */
public final MediaRouteSelector getMediaRouteSelector() {
    return mMediaRouteSelector;
}
 
Example #29
Source File: MediaRouteController.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * @return A new MediaRouteSelector filtering the remote playback devices from all the routes.
 */
MediaRouteSelector buildMediaRouteSelector();
 
Example #30
Source File: MediaRouteController.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * @return A new MediaRouteSelector filtering the remote playback devices from all the routes.
 */
MediaRouteSelector buildMediaRouteSelector();