Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/MediaRouteController.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/MediaRouteController.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/MediaRouteController.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..67701ddb9f2e5a3c1c9efc9b3172a02e6be14053 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/MediaRouteController.java |
@@ -0,0 +1,240 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.media.remote; |
+ |
+import android.graphics.Bitmap; |
+import android.net.Uri; |
+import android.support.v7.media.MediaRouteSelector; |
+ |
+import org.chromium.third_party.android.media.ChromeMediaRouteControllerDialog; |
whywhat
2015/02/25 16:31:31
nit: not sorted in alphabetical order (this import
aberent
2015/03/11 18:29:57
Done.
|
+import org.chromium.base.VisibleForTesting; |
+import org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState; |
+ |
+/** |
+ * Each MediaRouteController controls the routes to devices which support remote playback of |
+ * particular categories of Media elements (e.g. all YouTube media elements, all media elements |
+ * with simple http source URLs). The MediaRouteController is responsible for configuring |
+ * and controlling remote playback of the media elements it supports. |
+ */ |
+public interface MediaRouteController extends ChromeMediaRouteControllerDialog.DisconnectListener, |
+ TransportControl.Listener { |
+ /** |
+ * Listener for events that are relevant to the state of the media and the media controls |
+ */ |
+ public interface MediaStateListener { |
+ /** |
+ * @param available whether routes are available. |
+ */ |
+ public void onRouteAvailabilityChanged(boolean available); |
+ |
+ public void onError(); |
+ |
+ public void onSeekCompleted(); |
+ |
+ public void onPrepared(); |
+ |
+ /** |
+ * @param name the name of the route |
+ */ |
+ public void onRouteSelected(String name); |
+ |
+ public void onRouteUnselected(); |
+ |
+ public void onPlaybackStateChanged(PlayerState newState); |
+ |
+ /** |
+ * @return the title of the video |
+ */ |
+ public String getTitle(); |
+ |
+ /** |
+ * @return the poster bitmap |
+ */ |
+ public Bitmap getPosterBitmap(); |
+ } |
+ |
+ /** |
+ * Listener for events that are relevant to the Browser UI. |
+ */ |
+ public interface UiListener { |
+ void onRouteSelected(String name, MediaRouteController mediaRouteController); |
+ |
+ void onRouteUnselected(MediaRouteController mediaRouteController); |
+ |
+ void onPrepared(MediaRouteController mediaRouteController); |
+ |
+ void onError(int errorType, String message); |
+ |
+ void onPlaybackStateChanged(PlayerState oldState, PlayerState newState); |
+ |
+ void onDurationUpdated(int durationMillis); |
+ |
+ void onPositionChanged(int positionMillis); |
+ |
+ void onTitleChanged(String title); |
+ } |
+ |
+ /** |
+ * Scan routes, and set up the MediaRouter object. This is called at every time we need to reset |
+ * the state. Because of that, this function is idempotent. If that changes in the future, where |
+ * this function gets called needs to be re-evaluated. |
+ * |
+ * @return false if device doesn't support cast, true otherwise. |
+ */ |
+ public boolean initialize(); |
+ |
+ /** |
+ * Can this mediaRouteController handle a media element? |
+ * @param sourceUrl the source |
+ * @param frameUrl |
+ * @return true if it can, false if it can't. |
+ */ |
+ public boolean canPlayMedia(String sourceUrl, String frameUrl); |
+ |
+ /** |
+ * @return A new MediaRouteSelector filtering the remote playback devices from all the routes. |
+ */ |
+ public MediaRouteSelector buildMediaRouteSelector(); |
+ |
+ /** |
+ * @return Whether there're remote playback devices available. |
+ */ |
+ public boolean isRemotePlaybackAvailable(); |
+ |
+ /** |
+ * @return Whether the currently selected device supports remote playback |
+ */ |
+ public boolean currentRouteSupportsRemotePlayback(); |
+ |
+ /** |
+ * Checks if we want to reconnect, and if so starts trying to do so. Otherwise clears out the |
+ * persistent request to reconnect. |
+ */ |
+ public boolean reconnectAnyExistingRoute(); |
+ |
+ /** |
+ * Sets the video URL when it becomes known. |
+ * |
+ * This is the original video URL but if there's URL redirection, it will change as resolved by |
+ * {@link MediaUrlResolver}. |
+ * |
+ * @param uri The video URL. |
+ */ |
+ public void setDataSource(Uri uri, String cookies); |
+ |
+ /** |
+ * Setup this object to discover new routes and register the necessary players. |
+ */ |
+ public void prepareMediaRoute(); |
+ |
+ /** |
+ * Add a Listener that will listen to events from this object |
+ * |
+ * @param listener the Listener that will receive the events |
+ */ |
+ public void addUiListener(UiListener listener); |
+ |
+ /** |
+ * Removes a Listener from this object |
+ * |
+ * @param listener the Listener to remove |
+ */ |
+ public void removeUiListener(UiListener listener); |
+ |
+ /** |
+ * @return The currently selected route's friendly name, or null if there is none selected |
+ */ |
+ public String getRouteName(); |
+ |
+ /** |
+ * @return true if this is currently using the default route, false if not. |
+ */ |
+ public boolean routeIsDefaultRoute(); |
+ |
+ /** |
+ * Called to prepare the remote playback asyncronously. onPrepared() of the current remote media |
+ * player object is called when the player is ready. |
+ * |
+ * @param startPositionMillis indicates where in the stream to start playing |
+ */ |
+ public void prepareAsync(String frameUrl, long startPositionMillis); |
+ |
+ /** |
+ * Sets the remote volume of the current route. |
+ * |
+ * @param delta The delta value. |
+ */ |
+ public void setRemoteVolume(int delta); |
+ |
+ /** |
+ * Resume paused playback of the current video. |
+ */ |
+ public void resume(); |
+ |
+ /** |
+ * Pauses the currently playing video if any. |
+ */ |
+ public void pause(); |
+ |
+ /** |
+ * Returns the current remote playback position. Estimates the current position by using the |
+ * last known position and the current time. |
+ * |
+ * TODO(avayvod): Send periodic status update requests to update the position once in several |
+ * seconds or so. |
+ * |
+ * @return The current position of the remote playback in milliseconds. |
+ */ |
+ public int getPosition(); |
+ |
+ /** |
+ * @return The stream duration in milliseconds. |
+ */ |
+ public int getDuration(); |
+ |
+ /** |
+ * @return Whether the video is currently being played. |
+ */ |
+ public boolean isPlaying(); |
+ |
+ /** |
+ * @return Whether the video is being cast (any of playing/paused/loading/stopped). |
+ */ |
+ public boolean isBeingCast(); |
+ |
+ /** |
+ * Initiates a seek request for the remote playback device to the specified position. |
+ * |
+ * @param msec The position to seek to, in milliseconds. |
+ */ |
+ public void seekTo(int msec); |
+ |
+ /** |
+ * Stop the current remote playback completely and release all resources. |
+ */ |
+ public void release(); |
+ |
+ /** |
+ * @param player - the current player using this media route controller. |
+ */ |
+ public void setMediaStateListener(MediaStateListener listener); |
+ |
+ /** |
+ * @return the current VideoStateListener |
+ */ |
+ public MediaStateListener getMediaStateListener(); |
+ |
+ /** |
+ * @return true if the video is new |
+ */ |
+ public boolean shouldResetState(MediaStateListener newListener); |
+ |
+ @VisibleForTesting |
+ public PlayerState getPlayerState(); |
+ |
+ public void removeRouteAvailabilityListener(MediaStateListener listener); |
+ |
+ public void addRouteAvailabilityListener(MediaStateListener listener); |
+} |