public MediaRouterRouteInfoAssert hasName(String name) { isNotNull(); String actualName = actual.getName(); assertThat(actualName) // .overridingErrorMessage("Expected name <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
public MediaRouterRouteInfoAssert hasDescription(String description) { isNotNull(); String actualDescription = actual.getDescription(); assertThat(actualDescription) // .overridingErrorMessage("Expected description <%s> but was <%s>.", description, actualDescription) // .isEqualTo(description); return this; }
public MediaRouterRouteInfoAssert hasId(String id) { isNotNull(); String actualId = actual.getId(); assertThat(actualId) // .overridingErrorMessage("Expected id <%s> but was <%s>.", id, actualId) // .isEqualTo(id); return this; }
@Override public void updateStatistics() { // clear stats info first mStatsInfo = ""; Intent intent = new Intent(SampleMediaRouteProvider.ACTION_GET_STATISTICS); intent.addCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE); if (mRoute != null && mRoute.supportsControlRequest(intent)) { ControlRequestCallback callback = new ControlRequestCallback() { @Override public void onResult(Bundle data) { if (DEBUG) { Log.d(TAG, "getStatistics: succeeded: data=" + data); } if (data != null) { int playbackCount = data.getInt( SampleMediaRouteProvider.DATA_PLAYBACK_COUNT, -1); mStatsInfo = "Total playback count: " + playbackCount; } } @Override public void onError(String error, Bundle data) { Log.d(TAG, "getStatistics: failed: error=" + error + ", data=" + data); } }; mRoute.sendControlRequest(intent, callback); } }
private void sendControlIntent(final Intent intent, final ResultBundleHandler bundleHandler) { Log.d(TAG, "Sending intent to %s %s", getCurrentRoute().getName(), getCurrentRoute().getId()); logIntent("sendControlIntent ", intent); if (getCurrentRoute().isDefault()) { Log.d(TAG, "Route is default, not sending"); return; } getCurrentRoute().sendControlRequest(intent, new MediaRouter.ControlRequestCallback() { @Override public void onResult(Bundle data) { if (data != null && bundleHandler != null) bundleHandler.onResult(data); } @Override public void onError(String message, Bundle data) { logControlRequestError(intent, message, data); int errorCode = 0; if (data != null) { errorCode = data.getInt(CastMediaControlIntent.EXTRA_ERROR_CODE); } sendErrorToListeners(errorCode); if (bundleHandler != null) bundleHandler.onError(message, data); } }); }
@Override public void onRouteChanged(MediaRouter router, RouteInfo route) { // We only care about changes to the current route. if (!route.equals(getCurrentRoute())) return; // When there is no wifi connection, this condition becomes true. if (route.isConnecting()) { // We don't want to post the same Runnable twice. if (!mConnectionFailureNotifierQueued) { mConnectionFailureNotifierQueued = true; getHandler().postDelayed(mConnectionFailureNotifier, CONNECTION_FAILURE_NOTIFICATION_DELAY_MS); } } else { // Only cancel the disconnect if we already posted the message. We can get into this // situation if we swap the current route provider (for example, switching to a YT // video while casting a non-YT video). if (mConnectionFailureNotifierQueued) { // We have reconnected, cancel the delayed disconnect. getHandler().removeCallbacks(mConnectionFailureNotifier); mConnectionFailureNotifierQueued = false; } } }
@Override protected void onRouteSelectedEvent(MediaRouter router, RouteInfo route) { Log.d(TAG, "Selected route %s", route); if (!route.isSelected()) return; RecordCastAction.castPlayRequested(); RecordCastAction.remotePlaybackDeviceSelected( RecordCastAction.DEVICE_TYPE_CAST_GENERIC); installBroadcastReceivers(); if (getMediaStateListener() == null) { showCastError(route.getName()); release(); return; } if (route != getCurrentRoute()) { registerRoute(route); clearStreamState(); } mPositionExtrapolator.clear(); notifyRouteSelected(route); }
public static Player create(Context context, RouteInfo route) { Player player; if (route != null && route.supportsControlCategory( MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) { player = new RemotePlayer(context); } else if (route != null) { player = new LocalPlayer.SurfaceViewPlayer(context); } else { player = new LocalPlayer.OverlayPlayer(context); } player.connect(route); return player; }
@Override public final String getRouteName() { return mCurrentRoute == null ? null : mCurrentRoute.getName(); }
/** * Reset the media route to the default */ protected void clearMediaRoute() { if (getMediaRouter() != null) { getMediaRouter().getDefaultRoute().select(); registerRoute(getMediaRouter().getDefaultRoute()); } }
protected void sendErrorToListeners(int error) { String errorMessage = getContext().getString(R.string.cast_error_playing_video, mCurrentRoute.getName()); for (UiListener listener : mUiListeners) { listener.onError(error, errorMessage); } if (mMediaStateListener != null) mMediaStateListener.onError(); }
@Override public final boolean isRemotePlaybackAvailable() { if (mediaRouterInitializationFailed()) return false; return getMediaRouter().getSelectedRoute().getPlaybackType() == MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE || getMediaRouter().isRouteAvailable( mMediaRouteSelector, MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE); }
@Override public boolean currentRouteSupportsRemotePlayback() { return mCurrentRoute != null && mCurrentRoute.supportsControlCategory( MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); }
@Override protected void onRouteUnselectedEvent(MediaRouter router, RouteInfo route) { Log.d(TAG, "Unselected route %s", route); // Preserve our best guess as to the final position; this is needed to reset the // local position while switching back to local playback. mPositionExtrapolator.onPaused(); if (getCurrentRoute() != null && route.getId().equals(getCurrentRoute().getId())) { clearStreamState(); } }
protected final void notifyRouteSelected(RouteInfo route) { for (UiListener listener : mUiListeners) { listener.onRouteSelected(route.getName(), this); } if (!canCastMedia()) return; if (mMediaStateListener == null) return; mMediaStateListener.pauseLocal(); mMediaStateListener.onCastStarting(route.getName()); startCastingVideo(); }
@Override public void onRouteUnselected(MediaRouter router, RouteInfo route) { onRouteUnselectedEvent(router, route); if (getCurrentRoute() != null && !getCurrentRoute().isDefault() && route.getId().equals(getCurrentRoute().getId())) { RecordCastAction.castEndedTimeRemaining(getDuration(), getDuration() - getPosition()); release(); } } }
@Override public void setRemoteVolume(int delta) { boolean canChangeRemoteVolume = (getCurrentRoute().getVolumeHandling() == MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE); if (currentRouteSupportsRemotePlayback() && canChangeRemoteVolume) { getCurrentRoute().requestUpdateVolume(delta); } }
/** * @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())); }
private void updateRouteDescription() { RouteInfo route = mMediaRouter.getSelectedRoute(); mInfoTextView.setText( "Currently selected route:" + "\nName: " + route.getName() + "\nProvider: " + route.getProvider().getPackageName() + "\nDescription: " + route.getDescription() + "\nStatistics: " + mSessionManager.getStatistics()); }