Merge "Update media router API." into jb-mr2-dev
This commit is contained in:
@@ -46,7 +46,26 @@
|
|||||||
<!-- MediaRouter Support Samples -->
|
<!-- MediaRouter Support Samples -->
|
||||||
|
|
||||||
<activity android:name=".media.SampleMediaRouterActivity"
|
<activity android:name=".media.SampleMediaRouterActivity"
|
||||||
android:label="@string/sample_media_router_activity">
|
android:label="@string/sample_media_router_activity_dark"
|
||||||
|
android:theme="@style/Theme.AppCompat">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".media.SampleMediaRouterActivity$Light"
|
||||||
|
android:label="@string/sample_media_router_activity_light"
|
||||||
|
android:theme="@style/Theme.AppCompat.Light">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".media.SampleMediaRouterActivity$LightWithDarkActionBar"
|
||||||
|
android:label="@string/sample_media_router_activity_light_with_dark_action_bar"
|
||||||
|
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
|
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
|
||||||
@@ -55,7 +74,7 @@
|
|||||||
|
|
||||||
<service android:name=".media.SampleMediaRouteProviderService"
|
<service android:name=".media.SampleMediaRouteProviderService"
|
||||||
android:label="@string/sample_media_route_provider_service"
|
android:label="@string/sample_media_route_provider_service"
|
||||||
android:process=":mediarouteprovider">
|
android:process=":mrp">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.media.MediaRouteProviderService" />
|
<action android:name="android.media.MediaRouteProviderService" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (C) 2012 Google Inc.
|
<!-- Copyright (C) 2013 Google Inc.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<!-- TODO: Use MediaRouter support library -->
|
<item android:id="@+id/media_route_menu_item"
|
||||||
<item android:id="@+id/menu_media_route"
|
android:title="@string/media_route_menu_title"
|
||||||
android:title="@string/sample_media_router_play_on"
|
app:showAsAction="always"
|
||||||
android:showAsAction="always"
|
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"/>
|
||||||
android:orderInCategory="1"
|
|
||||||
android:actionProviderClass="android.app.MediaRouteActionProvider"/>
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|||||||
@@ -19,10 +19,12 @@
|
|||||||
|
|
||||||
<!-- MediaRouter -->
|
<!-- MediaRouter -->
|
||||||
|
|
||||||
<string name="sample_media_router_activity">MediaRouter</string>
|
<string name="sample_media_router_activity_dark">MediaRouter/Dark Theme</string>
|
||||||
|
<string name="sample_media_router_activity_light">MediaRouter/Light Theme</string>
|
||||||
|
<string name="sample_media_router_activity_light_with_dark_action_bar">MediaRouter/Light Theme, Dark Action Bar</string>
|
||||||
<string name="sample_media_router_text">This activity demonstrates how to
|
<string name="sample_media_router_text">This activity demonstrates how to
|
||||||
use MediaRouter from the support library. Select a route from the action bar.</string>
|
use MediaRouter from the support library. Select a route from the action bar.</string>
|
||||||
<string name="sample_media_router_play_on">Play on...</string>
|
<string name="media_route_menu_title">Play on...</string>
|
||||||
|
|
||||||
<string name="play_button_text">Play</string>
|
<string name="play_button_text">Play</string>
|
||||||
<string name="statistics_button_text">Show Statistics</string>
|
<string name="statistics_button_text">Show Statistics</string>
|
||||||
|
|||||||
@@ -29,9 +29,12 @@ import android.os.Bundle;
|
|||||||
import android.support.v7.media.MediaControlIntent;
|
import android.support.v7.media.MediaControlIntent;
|
||||||
import android.support.v7.media.MediaRouteProvider;
|
import android.support.v7.media.MediaRouteProvider;
|
||||||
import android.support.v7.media.MediaRouter.ControlRequestCallback;
|
import android.support.v7.media.MediaRouter.ControlRequestCallback;
|
||||||
|
import android.support.v7.media.MediaRouteProviderDescriptor;
|
||||||
|
import android.support.v7.media.MediaRouteDescriptor;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +54,7 @@ final class SampleMediaRouteProvider extends MediaRouteProvider {
|
|||||||
* supported by this provider's routes.
|
* supported by this provider's routes.
|
||||||
*/
|
*/
|
||||||
public static final String CATEGORY_SAMPLE_ROUTE =
|
public static final String CATEGORY_SAMPLE_ROUTE =
|
||||||
"com.example.android.supportv4.media.CATEGORY_SAMPLE_ROUTE";
|
"com.example.android.supportv7.media.CATEGORY_SAMPLE_ROUTE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom media control intent action for special requests that are
|
* A custom media control intent action for special requests that are
|
||||||
@@ -64,29 +67,31 @@ final class SampleMediaRouteProvider extends MediaRouteProvider {
|
|||||||
* @see #DATA_PLAYBACK_COUNT
|
* @see #DATA_PLAYBACK_COUNT
|
||||||
*/
|
*/
|
||||||
public static final String ACTION_GET_STATISTICS =
|
public static final String ACTION_GET_STATISTICS =
|
||||||
"com.example.android.supportv4.media.ACTION_GET_STATISTICS";
|
"com.example.android.supportv7.media.ACTION_GET_STATISTICS";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link #ACTION_GET_STATISTICS} result data: Number of times the
|
* {@link #ACTION_GET_STATISTICS} result data: Number of times the
|
||||||
* playback action was invoked.
|
* playback action was invoked.
|
||||||
*/
|
*/
|
||||||
public static final String DATA_PLAYBACK_COUNT =
|
public static final String DATA_PLAYBACK_COUNT =
|
||||||
"com.example.android.supportv4.media.EXTRA_PLAYBACK_COUNT";
|
"com.example.android.supportv7.media.EXTRA_PLAYBACK_COUNT";
|
||||||
|
|
||||||
private static final IntentFilter[] CONTROL_FILTERS;
|
private static final ArrayList<IntentFilter> CONTROL_FILTERS;
|
||||||
static {
|
static {
|
||||||
CONTROL_FILTERS = new IntentFilter[2];
|
IntentFilter f1 = new IntentFilter();
|
||||||
|
f1.addCategory(CATEGORY_SAMPLE_ROUTE);
|
||||||
|
f1.addAction(ACTION_GET_STATISTICS);
|
||||||
|
|
||||||
CONTROL_FILTERS[0] = new IntentFilter();
|
IntentFilter f2 = new IntentFilter();
|
||||||
CONTROL_FILTERS[0].addCategory(CATEGORY_SAMPLE_ROUTE);
|
f2.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
|
||||||
CONTROL_FILTERS[0].addAction(ACTION_GET_STATISTICS);
|
f2.addAction(MediaControlIntent.ACTION_PLAY);
|
||||||
|
f2.addDataScheme("http");
|
||||||
|
f2.addDataScheme("https");
|
||||||
|
addDataTypeUnchecked(f2, "video/*");
|
||||||
|
|
||||||
CONTROL_FILTERS[1] = new IntentFilter();
|
CONTROL_FILTERS = new ArrayList<IntentFilter>();
|
||||||
CONTROL_FILTERS[1].addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
|
CONTROL_FILTERS.add(f1);
|
||||||
CONTROL_FILTERS[1].addAction(MediaControlIntent.ACTION_PLAY);
|
CONTROL_FILTERS.add(f2);
|
||||||
CONTROL_FILTERS[1].addDataScheme("http");
|
|
||||||
CONTROL_FILTERS[1].addDataScheme("https");
|
|
||||||
addDataTypeUnchecked(CONTROL_FILTERS[1], "video/*");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
|
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
|
||||||
@@ -114,29 +119,33 @@ final class SampleMediaRouteProvider extends MediaRouteProvider {
|
|||||||
private void publishRoutes() {
|
private void publishRoutes() {
|
||||||
Resources r = getContext().getResources();
|
Resources r = getContext().getResources();
|
||||||
|
|
||||||
RouteDescriptor routeDescriptor1 = new RouteDescriptor(
|
MediaRouteDescriptor routeDescriptor1 = new MediaRouteDescriptor.Builder(
|
||||||
FIXED_VOLUME_ROUTE_ID,
|
FIXED_VOLUME_ROUTE_ID,
|
||||||
r.getString(R.string.fixed_volume_route_name));
|
r.getString(R.string.fixed_volume_route_name))
|
||||||
routeDescriptor1.setControlFilters(CONTROL_FILTERS);
|
.addControlFilters(CONTROL_FILTERS)
|
||||||
routeDescriptor1.setIconResource(R.drawable.media_route_icon);
|
.setIconResource(R.drawable.media_route_icon)
|
||||||
routeDescriptor1.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE);
|
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
|
||||||
routeDescriptor1.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED);
|
.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED)
|
||||||
routeDescriptor1.setVolume(VOLUME_MAX);
|
.setVolume(VOLUME_MAX)
|
||||||
|
.build();
|
||||||
|
|
||||||
RouteDescriptor routeDescriptor2 = new RouteDescriptor(
|
MediaRouteDescriptor routeDescriptor2 = new MediaRouteDescriptor.Builder(
|
||||||
VARIABLE_VOLUME_ROUTE_ID,
|
VARIABLE_VOLUME_ROUTE_ID,
|
||||||
r.getString(R.string.variable_volume_route_name));
|
r.getString(R.string.variable_volume_route_name))
|
||||||
routeDescriptor2.setControlFilters(CONTROL_FILTERS);
|
.addControlFilters(CONTROL_FILTERS)
|
||||||
routeDescriptor2.setIconResource(R.drawable.media_route_icon);
|
.setIconResource(R.drawable.media_route_icon)
|
||||||
routeDescriptor2.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE);
|
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
|
||||||
routeDescriptor2.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);
|
.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE)
|
||||||
routeDescriptor2.setVolumeMax(VOLUME_MAX);
|
.setVolumeMax(VOLUME_MAX)
|
||||||
routeDescriptor2.setVolume(mVolume);
|
.setVolume(mVolume)
|
||||||
|
.build();
|
||||||
|
|
||||||
ProviderDescriptor providerDescriptor = new ProviderDescriptor();
|
MediaRouteProviderDescriptor providerDescriptor =
|
||||||
providerDescriptor.setRoutes(new RouteDescriptor[] {
|
new MediaRouteProviderDescriptor.Builder()
|
||||||
routeDescriptor1, routeDescriptor2
|
.addRoute(routeDescriptor1)
|
||||||
});
|
.addRoute(routeDescriptor2)
|
||||||
|
.addDiscoverableControlFilters(CONTROL_FILTERS)
|
||||||
|
.build();
|
||||||
setDescriptor(providerDescriptor);
|
setDescriptor(providerDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,17 @@ package com.example.android.supportv7.media;
|
|||||||
|
|
||||||
import com.example.android.supportv7.R;
|
import com.example.android.supportv7.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.MediaRouteActionProvider;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.support.v7.app.MediaRouteActionProvider;
|
||||||
import android.support.v7.media.MediaControlIntent;
|
import android.support.v7.media.MediaControlIntent;
|
||||||
import android.support.v7.media.MediaRouter;
|
import android.support.v7.media.MediaRouter;
|
||||||
import android.support.v7.media.MediaRouter.RouteInfo;
|
import android.support.v7.media.MediaRouter.RouteInfo;
|
||||||
import android.support.v7.media.MediaRouter.ProviderInfo;
|
import android.support.v7.media.MediaRouter.ProviderInfo;
|
||||||
|
import android.support.v7.media.MediaRouteSelector;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -49,10 +51,11 @@ import android.widget.Toast;
|
|||||||
* targets.
|
* targets.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class SampleMediaRouterActivity extends Activity {
|
public class SampleMediaRouterActivity extends ActionBarActivity {
|
||||||
private final String TAG = "MediaRouterSupport";
|
private final String TAG = "MediaRouterSupport";
|
||||||
|
|
||||||
private MediaRouter mMediaRouter;
|
private MediaRouter mMediaRouter;
|
||||||
|
private MediaRouteSelector mSelector;
|
||||||
private ArrayAdapter<MediaItem> mMediaItems;
|
private ArrayAdapter<MediaItem> mMediaItems;
|
||||||
private TextView mInfoTextView;
|
private TextView mInfoTextView;
|
||||||
private ListView mMediaListView;
|
private ListView mMediaListView;
|
||||||
@@ -67,6 +70,14 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
// Get the media router service.
|
// Get the media router service.
|
||||||
mMediaRouter = MediaRouter.getInstance(this);
|
mMediaRouter = MediaRouter.getInstance(this);
|
||||||
|
|
||||||
|
// Create a route selector for the type of routes that we care about.
|
||||||
|
mSelector = new MediaRouteSelector.Builder()
|
||||||
|
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
|
||||||
|
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
|
||||||
|
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
|
||||||
|
.addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Populate an array adapter with fake media items.
|
// Populate an array adapter with fake media items.
|
||||||
String[] mediaNames = getResources().getStringArray(R.array.media_names);
|
String[] mediaNames = getResources().getStringArray(R.array.media_names);
|
||||||
String[] mediaUris = getResources().getStringArray(R.array.media_uris);
|
String[] mediaUris = getResources().getStringArray(R.array.media_uris);
|
||||||
@@ -114,7 +125,8 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
// Listen for changes to media routes.
|
// Listen for changes to media routes.
|
||||||
mMediaRouter.addCallback(mMediaRouterCallback);
|
mMediaRouter.addCallback(mSelector, mCallback,
|
||||||
|
MediaRouter.CALLBACK_FLAG_UNFILTERED_EVENTS);
|
||||||
updateRouteStatus();
|
updateRouteStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,10 +136,9 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
// Stop listening for changes to media routes.
|
// Stop listening for changes to media routes.
|
||||||
mMediaRouter.removeCallback(mMediaRouterCallback);
|
mMediaRouter.removeCallback(mCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use ActionBar support library.
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Be sure to call the super class.
|
// Be sure to call the super class.
|
||||||
@@ -136,14 +147,10 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
// Inflate the menu and configure the media router action provider.
|
// Inflate the menu and configure the media router action provider.
|
||||||
getMenuInflater().inflate(R.menu.sample_media_router_menu, menu);
|
getMenuInflater().inflate(R.menu.sample_media_router_menu, menu);
|
||||||
|
|
||||||
// TODO: Use support library media route action provider.
|
MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
|
||||||
MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route);
|
|
||||||
MediaRouteActionProvider mediaRouteActionProvider =
|
MediaRouteActionProvider mediaRouteActionProvider =
|
||||||
(MediaRouteActionProvider)mediaRouteMenuItem.getActionProvider();
|
(MediaRouteActionProvider)MenuItemCompat.getActionProvider(mediaRouteMenuItem);
|
||||||
mediaRouteActionProvider.setRouteTypes(
|
mediaRouteActionProvider.setRouteSelector(mSelector);
|
||||||
android.media.MediaRouter.ROUTE_TYPE_LIVE_AUDIO
|
|
||||||
| android.media.MediaRouter.ROUTE_TYPE_LIVE_VIDEO
|
|
||||||
| android.media.MediaRouter.ROUTE_TYPE_USER);
|
|
||||||
|
|
||||||
// Return true to show the menu.
|
// Return true to show the menu.
|
||||||
return true;
|
return true;
|
||||||
@@ -277,7 +284,7 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final MediaRouter.Callback mMediaRouterCallback = new MediaRouter.Callback() {
|
private final MediaRouter.Callback mCallback = new MediaRouter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onRouteAdded(MediaRouter router, RouteInfo route) {
|
public void onRouteAdded(MediaRouter router, RouteInfo route) {
|
||||||
Log.d(TAG, "onRouteAdded: route=" + route);
|
Log.d(TAG, "onRouteAdded: route=" + route);
|
||||||
@@ -325,6 +332,11 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
public void onProviderRemoved(MediaRouter router, ProviderInfo provider) {
|
public void onProviderRemoved(MediaRouter router, ProviderInfo provider) {
|
||||||
Log.d(TAG, "onRouteProviderRemoved: provider=" + provider);
|
Log.d(TAG, "onRouteProviderRemoved: provider=" + provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderChanged(MediaRouter router, ProviderInfo provider) {
|
||||||
|
Log.d(TAG, "onRouteProviderChanged: provider=" + provider);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final class MediaItem {
|
private static final class MediaItem {
|
||||||
@@ -341,4 +353,18 @@ public class SampleMediaRouterActivity extends Activity {
|
|||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trivial subclass of this activity used to provide another copy of the
|
||||||
|
* same activity using a light theme instead of the dark theme.
|
||||||
|
*/
|
||||||
|
public static class Light extends SampleMediaRouterActivity {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trivial subclass of this activity used to provide another copy of the
|
||||||
|
* same activity using a light theme with dark action bar instead of the dark theme.
|
||||||
|
*/
|
||||||
|
public static class LightWithDarkActionBar extends SampleMediaRouterActivity {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user