OSDN Git Service

Allow empty strings in playFromSearch
authorRoboErik <epastern@google.com>
Tue, 2 Sep 2014 19:25:42 +0000 (12:25 -0700)
committerRoboErik <epastern@google.com>
Wed, 3 Sep 2014 00:39:46 +0000 (17:39 -0700)
This allows empty strings to be passed to playFromSearch to indicate
something should be chosen for the user and played. This makes it
consistent with INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH.

bug:17316566
Change-Id: I00ce8d252efa940e05568629e35198450c224a92

media/java/android/media/session/MediaController.java
media/java/android/media/session/MediaSession.java

index 12ee59e..4d4d646 100644 (file)
@@ -613,14 +613,18 @@ public final class MediaController {
 
         /**
          * Request that the player start playback for a specific search query.
+         * An empty or null query should be treated as a request to play any
+         * music.
          *
          * @param query The search query.
-         * @param extras Optional extras that can include extra information about the query.
+         * @param extras Optional extras that can include extra information
+         *            about the query.
          */
         public void playFromSearch(String query, Bundle extras) {
-            if (TextUtils.isEmpty(query)) {
-                throw new IllegalArgumentException(
-                        "You must specify a non-empty search query for playFromSearch.");
+            if (query == null) {
+                // This is to remain compatible with
+                // INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH
+                query = "";
             }
             try {
                 mSessionBinder.playFromSearch(query, extras);
index ae8ce4b..095f885 100644 (file)
@@ -771,7 +771,10 @@ public final class MediaSession {
         }
 
         /**
-         * Override to handle requests to begin playback from a search query.
+         * Override to handle requests to begin playback from a search query. An
+         * empty query indicates that the app may play any music. The
+         * implementation should attempt to make a smart choice about what to
+         * play.
          */
         public void onPlayFromSearch(String query, Bundle extras) {
         }