Update media router API.

Bug: 8175766
Change-Id: Ib93572738b912530e96f8772bf7961af4b57c0c7
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java
index ebf7e29..916710c 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteProvider.java
@@ -27,6 +27,7 @@
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v7.media.MediaControlIntent;
+import android.support.v7.media.MediaItemStatus;
 import android.support.v7.media.MediaRouteProvider;
 import android.support.v7.media.MediaRouter.ControlRequestCallback;
 import android.support.v7.media.MediaRouteProviderDescriptor;
@@ -212,24 +213,40 @@
                 int queueBehavior = intent.getIntExtra(
                         MediaControlIntent.EXTRA_ITEM_QUEUE_BEHAVIOR,
                         MediaControlIntent.ITEM_QUEUE_BEHAVIOR_PLAY_NOW);
-                int position = intent.getIntExtra(
-                        MediaControlIntent.EXTRA_ITEM_POSITION, 0);
+                double contentPosition = intent.getDoubleExtra(
+                        MediaControlIntent.EXTRA_ITEM_CONTENT_POSITION, 0);
                 Bundle metadata = intent.getBundleExtra(MediaControlIntent.EXTRA_ITEM_METADATA);
                 Bundle headers = intent.getBundleExtra(
                         MediaControlIntent.EXTRA_ITEM_HTTP_HEADERS);
-                String streamId = generateStreamId();
 
                 Log.d(TAG, mRouteId + ": Received play request, uri=" + uri
                         + ", queueBehavior=" + queueBehavior
-                        + ", position=" + position
+                        + ", contentPosition=" + contentPosition
                         + ", metadata=" + metadata
                         + ", headers=" + headers);
-                Toast.makeText(getContext(), "Route received play request: uri=" + uri,
-                        Toast.LENGTH_LONG).show();
-                if (callback != null) {
-                    Bundle result = new Bundle();
-                    result.putString(MediaControlIntent.EXTRA_ITEM_ID, streamId);
-                    callback.onResult(ControlRequestCallback.REQUEST_SUCCEEDED, result);
+
+                if (uri.toString().contains("hats")) {
+                    // Simulate generating an error whenever the uri contains the word 'hats'.
+                    Toast.makeText(getContext(), "Route rejected play request: uri=" + uri
+                            + ", no hats allowed!", Toast.LENGTH_LONG).show();
+                    if (callback != null) {
+                        callback.onError("Simulated error.  No hats allowed!", null);
+                    }
+                } else {
+                    Toast.makeText(getContext(), "Route received play request: uri=" + uri,
+                            Toast.LENGTH_LONG).show();
+                    String streamId = generateStreamId();
+                    if (callback != null) {
+                        MediaItemStatus status = new MediaItemStatus.Builder(
+                                MediaItemStatus.PLAYBACK_STATE_PLAYING)
+                                .setContentPosition(contentPosition)
+                                .build();
+
+                        Bundle result = new Bundle();
+                        result.putString(MediaControlIntent.EXTRA_ITEM_ID, streamId);
+                        result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS, status.asBundle());
+                        callback.onResult(result);
+                    }
                 }
                 return true;
             }
@@ -239,7 +256,7 @@
                 Bundle data = new Bundle();
                 data.putInt(DATA_PLAYBACK_COUNT, mPlaybackCount);
                 if (callback != null) {
-                    callback.onResult(ControlRequestCallback.REQUEST_SUCCEEDED, data);
+                    callback.onResult(data);
                 }
                 return true;
             }
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java
index 1acecc5..7e570f1 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java
@@ -189,26 +189,22 @@
             MediaRouter.ControlRequestCallback callback =
                     new MediaRouter.ControlRequestCallback() {
                 @Override
-                public void onResult(int result, Bundle data) {
-                    switch (result) {
-                        case REQUEST_SUCCEEDED: {
-                            String streamId = data != null ? data.getString(
-                                    MediaControlIntent.EXTRA_ITEM_ID) : null;
+                public void onResult(Bundle data) {
+                    String streamId = data != null ? data.getString(
+                            MediaControlIntent.EXTRA_ITEM_ID) : null;
 
-                            Log.d(TAG, "Play request succeeded: streamId=" + streamId);
-                            Toast.makeText(SampleMediaRouterActivity.this,
-                                    "Now playing " + item.mName,
-                                    Toast.LENGTH_LONG).show();
-                            break;
-                        }
+                    Log.d(TAG, "Play request succeeded: data=" + data + " , streamId=" + streamId);
+                    Toast.makeText(SampleMediaRouterActivity.this,
+                            "Now playing " + item.mName,
+                            Toast.LENGTH_LONG).show();
+                }
 
-                        case REQUEST_FAILED:
-                            Log.d(TAG, "Play request failed.");
-                            Toast.makeText(SampleMediaRouterActivity.this,
-                                    "Unable to play " + item.mName,
-                                    Toast.LENGTH_LONG).show();
-                            break;
-                    }
+                @Override
+                public void onError(String error, Bundle data) {
+                    Log.d(TAG, "Play request failed: error=" + error + ", data=" + data);
+                    Toast.makeText(SampleMediaRouterActivity.this,
+                            "Unable to play " + item.mName + ", error: " + error,
+                            Toast.LENGTH_LONG).show();
                 }
             };
 
@@ -227,31 +223,28 @@
         if (route.supportsControlRequest(intent)) {
             MediaRouter.ControlRequestCallback callback = new MediaRouter.ControlRequestCallback() {
                 @Override
-                public void onResult(int result, Bundle data) {
-                    switch (result) {
-                        case REQUEST_SUCCEEDED:
-                            Log.d(TAG, "Statistics request succeeded: data=" + data);
-                            if (data != null) {
-                                int playbackCount = data.getInt(
-                                        SampleMediaRouteProvider.DATA_PLAYBACK_COUNT, -1);
-                                Toast.makeText(SampleMediaRouterActivity.this,
-                                        "Total playback count: " + playbackCount,
-                                        Toast.LENGTH_LONG).show();
-                            } else {
-                                Toast.makeText(SampleMediaRouterActivity.this,
-                                        "Statistics query did not return any data",
-                                        Toast.LENGTH_LONG).show();
-                            }
-                            break;
-
-                        case REQUEST_FAILED:
-                            Log.d(TAG, "Statistics request failed: data=" + data);
-                            Toast.makeText(SampleMediaRouterActivity.this,
-                                    "Unable to query statistics.",
-                                    Toast.LENGTH_LONG).show();
-                            break;
+                public void onResult(Bundle data) {
+                    Log.d(TAG, "Statistics request succeeded: data=" + data);
+                    if (data != null) {
+                        int playbackCount = data.getInt(
+                                SampleMediaRouteProvider.DATA_PLAYBACK_COUNT, -1);
+                        Toast.makeText(SampleMediaRouterActivity.this,
+                                "Total playback count: " + playbackCount,
+                                Toast.LENGTH_LONG).show();
+                    } else {
+                        Toast.makeText(SampleMediaRouterActivity.this,
+                                "Statistics query did not return any data",
+                                Toast.LENGTH_LONG).show();
                     }
                 }
+
+                @Override
+                public void onError(String error, Bundle data) {
+                    Log.d(TAG, "Statistics request failed: error=" + error + ", data=" + data);
+                    Toast.makeText(SampleMediaRouterActivity.this,
+                            "Unable to query statistics, error: " + error,
+                            Toast.LENGTH_LONG).show();
+                }
             };
 
             Log.d(TAG, "Sent statistics request: intent=" + intent);