Java Code Examples for android.support.v7.media.MediaRouter#getInstance()

The following examples show how to use android.support.v7.media.MediaRouter#getInstance() . 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
/************************************************************************/

    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 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: MediaRouteChooserDialogFactory.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);

    if (mCancelled) {
        if (mPlayer != null) mPlayer.onRouteDialogCancelled();
        return;
    }

    if (mController != null) {
        MediaRouter router = MediaRouter.getInstance(mContext);
        mController.onRouteSelected(mPlayer, router, router.getSelectedRoute());
    }
}
 
Example 4
Source File: AbstractMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
protected AbstractMediaRouteController() {
    mContext = ContextUtils.getApplicationContext();
    assert (getContext() != null);

    mHandler = new Handler();

    mMediaRouteSelector = buildMediaRouteSelector();

    MediaRouter mediaRouter;

    try {
        // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
        // so getting the MediaRouter instance will throw an exception.
        mediaRouter = MediaRouter.getInstance(getContext());
    } catch (NoSuchMethodError e) {
        Log.e(TAG, "Can't get an instance of MediaRouter, casting is not supported."
                + " Are you still on JB (JVP15S)?");
        mediaRouter = null;
    }
    mMediaRouter = mediaRouter;

    mAvailableRouteListeners = new HashSet<MediaStateListener>();
    // TODO(aberent): I am unclear why this is accessed from multiple threads, but
    // if I make it a HashSet then it gets ConcurrentModificationExceptions on some
    // types of disconnect. Investigate and fix.
    mUiListeners = new CopyOnWriteArraySet<UiListener>();

    mDeviceDiscoveryCallback = new DeviceDiscoveryCallback();
    mDeviceSelectionCallback = new DeviceSelectionCallback();
}
 
Example 5
Source File: MediaRouteChooserDialogFactory.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);

    if (mCancelled) {
        if (mPlayer != null) mPlayer.onRouteDialogCancelled();
        return;
    }

    if (mController != null) {
        MediaRouter router = MediaRouter.getInstance(mContext);
        mController.onRouteSelected(mPlayer, router, router.getSelectedRoute());
    }
}
 
Example 6
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected AbstractMediaRouteController() {
    mContext = ContextUtils.getApplicationContext();
    assert (getContext() != null);

    mHandler = new Handler();

    mMediaRouteSelector = buildMediaRouteSelector();

    MediaRouter mediaRouter;

    try {
        // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
        // so getting the MediaRouter instance will throw an exception.
        mediaRouter = MediaRouter.getInstance(getContext());
    } catch (NoSuchMethodError e) {
        Log.e(TAG, "Can't get an instance of MediaRouter, casting is not supported."
                + " Are you still on JB (JVP15S)?");
        mediaRouter = null;
    }
    mMediaRouter = mediaRouter;

    mAvailableRouteListeners = new HashSet<MediaStateListener>();
    // TODO(aberent): I am unclear why this is accessed from multiple threads, but
    // if I make it a HashSet then it gets ConcurrentModificationExceptions on some
    // types of disconnect. Investigate and fix.
    mUiListeners = new CopyOnWriteArraySet<UiListener>();

    mDeviceDiscoveryCallback = new DeviceDiscoveryCallback();
    mDeviceSelectionCallback = new DeviceSelectionCallback();
}
 
Example 7
Source File: MediaRouteChooserDialogFactory.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);

    if (mCancelled) {
        if (mPlayer != null) mPlayer.onRouteDialogCancelled();
        return;
    }

    if (mController != null) {
        MediaRouter router = MediaRouter.getInstance(mContext);
        mController.onRouteSelected(mPlayer, router, router.getSelectedRoute());
    }
}
 
Example 8
Source File: AbstractMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected AbstractMediaRouteController() {
    mContext = ContextUtils.getApplicationContext();
    assert (getContext() != null);

    mHandler = new Handler();

    mMediaRouteSelector = buildMediaRouteSelector();

    MediaRouter mediaRouter;

    try {
        // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
        // so getting the MediaRouter instance will throw an exception.
        mediaRouter = MediaRouter.getInstance(getContext());
    } catch (NoSuchMethodError e) {
        Log.e(TAG, "Can't get an instance of MediaRouter, casting is not supported."
                + " Are you still on JB (JVP15S)?");
        mediaRouter = null;
    }
    mMediaRouter = mediaRouter;

    mAvailableRouteListeners = new HashSet<MediaStateListener>();
    // TODO(aberent): I am unclear why this is accessed from multiple threads, but
    // if I make it a HashSet then it gets ConcurrentModificationExceptions on some
    // types of disconnect. Investigate and fix.
    mUiListeners = new CopyOnWriteArraySet<UiListener>();

    mDeviceDiscoveryCallback = new DeviceDiscoveryCallback();
    mDeviceSelectionCallback = new DeviceSelectionCallback();
}
 
Example 9
Source File: MediaRouteManager.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public MediaRouteManager(DownloadService downloadService) {
	this.downloadService = downloadService;
	router = MediaRouter.getInstance(downloadService);
	castAvailable = GoogleCompat.playServicesAvailable(downloadService) && GoogleCompat.castAvailable();

	addProviders();
	buildSelector();
}
 
Example 10
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();
}