@Override public void onAttach(Activity host) { super.onAttach(host); router=MediaRouter.getInstance(host); }
@Override public void onAttach(Activity host) { super.onAttach(host); router=MediaRouter.getInstance(host); provider=new DemoRouteProvider(getActivity()); router.addProvider(provider); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); selectedRoute=(TextView)findViewById(R.id.selected_route); router=MediaRouter.getInstance(this); selector= new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO) .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); preso= PresoRoster .getInstance() .getPresoById(getIntent().getIntExtra(EXTRA_PRESO_ID, 0)); setContentView(R.layout.activity_main); pager=(ViewPager)findViewById(R.id.pager); helper=new PresentationHelper(this, this); selector= new MediaRouteSelector.Builder() .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .build(); router=MediaRouter.getInstance(this); router.addCallback(selector, routeCB, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY); if (isDirectToTV()) { getSupportActionBar().hide(); } setupPager(); }
/** * Obtains the {@link MediaRouter} instance given the application context. * @param applicationContext The context to get the Android media router service for. * @return Null if the media router API is not supported, the service instance otherwise. */ @Nullable public static MediaRouter getAndroidMediaRouter(Context applicationContext) { try { // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, // so getting the MediaRouter instance will throw an exception. return MediaRouter.getInstance(applicationContext); } catch (NoSuchMethodError e) { return null; } catch (NoClassDefFoundError e) { // TODO(mlamouri): happens with Robolectric. return null; } }
@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()); } } }
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(); }
mMediaRouter = MediaRouter.getInstance(this);
private void updateMediaSession() { if (!mMediaNotificationInfo.supportsPlayPause()) return; if (mMediaSession == null) mMediaSession = createMediaSession(); try { // Tell the MediaRouter about the session, so that Chrome can control the volume // on the remote cast device (if any). // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, // so getting the MediaRouter instance will throw an exception. MediaRouter.getInstance(mContext).setMediaSessionCompat(mMediaSession); } catch (NoSuchMethodError e) { // Do nothing. Chrome can't be casting without a MediaRouter, so there is nothing // to do here. } mMediaSession.setMetadata(createMetadata()); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder().setActions( PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE); if (mMediaNotificationInfo.isPaused) { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } else { // If notification only supports stop, still pretend playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } mMediaSession.setPlaybackState(playbackStateBuilder.build()); }