| Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java
|
| index b770fe5246440130487035a72cf65434f9e32472..fac9f5c0b57c3de4c0e2384bdd07fc2d7b3c3234 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java
|
| @@ -180,9 +180,6 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| private final Set<UiListener> mUiListeners;
|
| private boolean mWatchingRouteSelection = false;
|
|
|
| - /**
|
| - * Sole constructor
|
| - */
|
| protected AbstractMediaRouteController() {
|
|
|
| mDebug = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CAST_DEBUG_LOGS);
|
| @@ -285,9 +282,6 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| return mHandler;
|
| }
|
|
|
| - /**
|
| - * @return the mMediaRouter
|
| - */
|
| protected final MediaRouter getMediaRouter() {
|
| return mMediaRouter;
|
| }
|
| @@ -307,10 +301,6 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| return mCurrentRoute == null ? null : mCurrentRoute.getName();
|
| }
|
|
|
| - /**
|
| - * @return The list of MediaRouteController.Listener objects that will receive messages from
|
| - * this class.
|
| - */
|
| protected final Set<UiListener> getUiListeners() {
|
| return mUiListeners;
|
| }
|
| @@ -347,7 +337,23 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| for (UiListener listener : mUiListeners) {
|
| listener.onRouteSelected(route.getName(), this);
|
| }
|
| - if (mMediaStateListener != null) mMediaStateListener.onRouteSelected(route.getName());
|
| + if (mMediaStateListener == null) return;
|
| + if (!canCastMedia()) return;
|
| + startCastingVideo(route);
|
| + }
|
| +
|
| + private void startCastingVideo(RouteInfo route) {
|
| + mMediaStateListener.pauseLocal();
|
| + mMediaStateListener.onCastStarting(route.getName());
|
| + setDataSource(Uri.parse(mMediaStateListener.getSourceUrl()),
|
| + mMediaStateListener.getCookies(), mMediaStateListener.getUserAgent());
|
| + prepareAsync(
|
| + mMediaStateListener.getFrameUrl(), mMediaStateListener.getStartPositionMillis());
|
| + }
|
| +
|
| + private boolean canCastMedia() {
|
| + return isRemotePlaybackAvailable() && !routeIsDefaultRoute()
|
| + && currentRouteSupportsRemotePlayback();
|
| }
|
|
|
| @Override
|
| @@ -440,12 +446,17 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| mMediaStateListener = mediaStateListener;
|
| }
|
|
|
| - private void setPrepared() {
|
| + private void onCasting() {
|
| if (!mIsPrepared) {
|
| for (UiListener listener : mUiListeners) {
|
| listener.onPrepared(this);
|
| }
|
| - if (mMediaStateListener != null) mMediaStateListener.onPrepared();
|
| + if (mMediaStateListener.isPauseRequested()) pause();
|
| + if (mMediaStateListener.isSeekRequested()) {
|
| + seekTo(mMediaStateListener.getSeekLocation());
|
| + } else {
|
| + seekTo(mMediaStateListener.getLocalPosition());
|
| + }
|
| RecordCastAction.castDefaultPlayerResult(true);
|
| mIsPrepared = true;
|
| }
|
| @@ -551,12 +562,12 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| System.currentTimeMillis());
|
| RemotePlaybackSettings.setShouldReconnectToRemote(getContext(),
|
| !mCurrentRoute.isDefault());
|
| - setPrepared();
|
| + onCasting();
|
| break;
|
| case PAUSED:
|
| RemotePlaybackSettings.setShouldReconnectToRemote(getContext(),
|
| !mCurrentRoute.isDefault());
|
| - setPrepared();
|
| + onCasting();
|
| break;
|
| case FINISHED:
|
| release();
|
| @@ -600,4 +611,17 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll
|
| * @param cookies
|
| */
|
| public void setDataSource(Uri uri, String cookies) {};
|
| +
|
| + @Override
|
| + public boolean playerTakesOverCastDevice(MediaStateListener mediaStateListener) {
|
| + // Check if this MediaRouteControler is casting something.
|
| + if (!isBeingCast()) return false;
|
| + // Check if we want to cast the new video
|
| + if (!canCastMedia()) return false;
|
| + // Take over the cast device
|
| + if (mMediaStateListener != null) mMediaStateListener.onCastStopping();
|
| + mMediaStateListener = mediaStateListener;
|
| + startCastingVideo(mCurrentRoute);
|
| + return true;
|
| + }
|
| }
|
|
|