Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3935)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java

Issue 1403703005: Refactor Clank cast connect logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybot detected error. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/media/remote/MediaRouteController.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/media/remote/MediaRouteController.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698