MediaControlIntent.java revision b507e525a61ed761eecfc2eaaf19af7e8db5dca5
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v7.media;
18
19import android.content.Intent;
20import android.net.Uri;
21
22/**
23 * Constants for identifying media route capabilities and controlling media routes
24 * by sending an {@link Intent}.
25 * <p>
26 * The basic capabilities of a media route may be determined by looking at the
27 * media control intent categories and actions supported by the route.
28 * </p><ul>
29 * <li>A media control intent category specifies the type of the route
30 * and the manner in which applications send media to its destination.
31 * <li>A media control intent action specifies a command to be delivered to
32 * the media route's destination to control media playback.  Media control
33 * actions may only apply to routes that support certain media control categories.
34 * </ul>
35 */
36public final class MediaControlIntent {
37    /**
38     * Media control category: Live audio.
39     * <p>
40     * A route that supports live audio routing will allow the media audio stream
41     * to be sent to supported destinations.  This can include internal speakers or
42     * audio jacks on the device itself, A2DP devices, and more.
43     * </p><p>
44     * When a live audio route is selected, audio routing is transparent to the application.
45     * All audio played on the media stream will be routed to the selected destination.
46     * </p>
47     */
48    public static final String CATEGORY_LIVE_AUDIO = "android.media.intent.category.LIVE_AUDIO";
49
50    /**
51     * Media control category: Live video.
52     * <p>
53     * A route that supports live video routing will allow a mirrored version
54     * of the device's primary display or a customized
55     * {@link android.app.Presentation Presentation} to be sent to supported
56     * destinations.
57     * </p><p>
58     * When a live video route is selected, audio and video routing is transparent
59     * to the application.  By default, audio and video is routed to the selected
60     * destination.  For certain live video routes, the application may also use a
61     * {@link android.app.Presentation Presentation} to replace the mirrored view
62     * on the external display with different content.
63     * </p>
64     *
65     * @see MediaRouter.RouteInfo#getPresentationDisplay()
66     * @see android.app.Presentation
67     */
68    public static final String CATEGORY_LIVE_VIDEO = "android.media.intent.category.LIVE_VIDEO";
69
70    /**
71     * Media control category: Remote playback.
72     * <p>
73     * A route that supports remote playback routing will allow an application to send
74     * requests to play content remotely to supported destinations.
75     * </p><p>
76     * Remote playback routes destinations operate independently of the local device.
77     * When a remote playback route is selected, the application can control the content
78     * playing on the destination by sending media control actions to the route.
79     * The application may also receive status updates from the route regarding
80     * remote playback.
81     * </p>
82     *
83     * @see MediaRouter.RouteInfo#sendControlRequest
84     */
85    public static final String CATEGORY_REMOTE_PLAYBACK =
86            "android.media.intent.category.REMOTE_PLAYBACK";
87
88    /**
89     * Media control action: Play.
90     * <p>
91     * Used with routes that support {@link #CATEGORY_REMOTE_PLAYBACK remote playback}
92     * media control.
93     * </p><p>
94     * This action causes a remote playback route to start playing content with
95     * the {@link Uri} specified in the {@link Intent}'s {@link Intent#getData() data uri}.
96     * </p><p>
97     * Once initiated, playback of the specified content will be queued and managed
98     * independently by the destination.  The application will receive status
99     * and progress updates as the content is played.
100     * </p>
101     *
102     * <h3>Request parameters</h3>
103     * <ul>
104     * <li>{@link #EXTRA_QUEUE_BEHAVIOR} specifies when the content should be played.
105     * <li>{@link #EXTRA_STREAM_START_POSITION} specifies the start position of the
106     * content stream to play in seconds.
107     * <li>{@link #EXTRA_STREAM_END_POSITION} specifies the end position of the
108     * content stream to play in seconds.
109     * <li>{@link #EXTRA_STREAM_METADATA} specifies metadata associated with the
110     * content stream such as the title of a song.
111     * </ul>
112     *
113     * <h3>Result data</h3>
114     * <ul>
115     * <li>(none)
116     * </ul>
117     *
118     * <h3>Example</h3>
119     * <pre>
120     * MediaRouter mediaRouter = MediaRouter.getInstance(context);
121     * MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();
122     * Intent intent = new Intent(MediaControlIntent.ACTION_PLAY);
123     * intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
124     * intent.setDataAndType("http://example.com/videos/movie.mp4", "video/mp4");
125     * intent.putExtra(MediaControlIntent.EXTRA_QUEUE_BEHAVIOR,
126     *         MediaControlIntent.QUEUE_BEHAVIOR_PLAY_NEXT);
127     * if (route.supportsControlRequest(intent)) {
128     *     MediaRouter.ControlRequestCallback callback = new MediaRouter.ControlRequestCallback() {
129     *         public void onResult(int result, Bundle data) {
130     *             if (result == REQUEST_SUCCEEDED) {
131     *                 // request succeeded
132     *             }
133     *         }
134     *     };
135     *     route.sendControlRequest(intent, callback);
136     * }</pre>
137     *
138     * @see MediaRouter.RouteInfo#sendControlRequest
139     * @see #CATEGORY_REMOTE_PLAYBACK
140     */
141    public static final String ACTION_PLAY = "android.media.intent.action.PLAY";
142
143    /**
144     * Integer extra: Queue behavior.
145     * <p>
146     * Used with {@link #ACTION_PLAY} to specify when the requested content should be
147     * played.  The default is to play the content immediately.
148     * </p><p>
149     * The value must be one of {@link #QUEUE_BEHAVIOR_PLAY_NOW},
150     * {@link #QUEUE_BEHAVIOR_PLAY_NEXT}, or {@link #QUEUE_BEHAVIOR_PLAY_LATER}.
151     * </p>
152     *
153     * @see #ACTION_PLAY
154     */
155    public static final String EXTRA_QUEUE_BEHAVIOR =
156            "android.media.intent.extra.QUEUE_BEHAVIOR";
157
158    /**
159     * Value for {@link #EXTRA_QUEUE_BEHAVIOR}: Play now.
160     * <p>
161     * Requests that the new content play immediately, cancelling the currently playing
162     * media item.  (This is the default queue behavior.)
163     * </p>
164     *
165     * @see #EXTRA_QUEUE_BEHAVIOR
166     */
167    public final static int QUEUE_BEHAVIOR_PLAY_NOW = 0;
168
169    /**
170     * Value for {@link #EXTRA_QUEUE_BEHAVIOR}: Play next.
171     * <p>
172     * Requests that the new content be enqueued to play next after the currently playing
173     * media item.
174     * </p>
175     *
176     * @see #EXTRA_QUEUE_BEHAVIOR
177     */
178    public final static int QUEUE_BEHAVIOR_PLAY_NEXT = 1;
179
180    /**
181     * Value for {@link #EXTRA_QUEUE_BEHAVIOR}: Play later.
182     * <p>
183     * Requests that the new content be enqueued to play later after all other items
184     * currently in the queue.
185     * </p>
186     *
187     * @see #EXTRA_QUEUE_BEHAVIOR
188     */
189    public final static int QUEUE_BEHAVIOR_PLAY_LATER = 2;
190
191    /**
192     * Integer extra: Stream start position.
193     * <p>
194     * Used with {@link #ACTION_PLAY} to specify the starting playback position in
195     * seconds from the beginning of the content stream to be played.
196     * </p>
197     *
198     * @see #ACTION_PLAY
199     */
200    public static final String EXTRA_STREAM_START_POSITION =
201            "android.media.intent.extra.STREAM_START_POSITION";
202
203    /**
204     * Integer extra: Stream end position.
205     * <p>
206     * Used with {@link #ACTION_PLAY} to specify the ending playback position in
207     * seconds from the beginning of the content stream to be played.
208     * </p>
209     *
210     * @see #ACTION_PLAY
211     */
212    public static final String EXTRA_STREAM_END_POSITION =
213            "android.media.intent.extra.STREAM_END_POSITION";
214
215    /**
216     * Bundle extra: Stream metadata.
217     * <p>
218     * Used with {@link #ACTION_PLAY} to specify a {@link android.os.Bundle} of metadata that
219     * describes the media content stream to be played.  The valid metadata keys are
220     * defined in {@link MediaStreamMetadata}.
221     * </p>
222     *
223     * @see #ACTION_PLAY
224     */
225    public static final String EXTRA_STREAM_METADATA =
226            "android.media.intent.extra.STREAM_METADATA";
227
228    private MediaControlIntent() {
229    }
230}
231