android Media Route Provider

来源:互联网 发布:js全栈开发教程 编辑:程序博客网 时间:2024/06/06 18:11

》Users want to play media content from their Android devices bigger, brighter, and louder on connected playback devices such as televisions, stereos, and home theater equipment. As a manufacturer of these devices, allowing Android users to instantly show a picture, play a song, or share a video for friends and family using your product can make it much more compelling and engaging.

》a media route provider service:extends MediaRouteProviderService
The media router framework allows you to define and publish the capabilities of your media route throughIntentFilter objects, MediaRouteDescriptor objects and a MediaRouteProviderDescriptor

》You specify these settings using the IntentFilter class and the addDataScheme() andaddDataType() methods of that object. The following code snippet demonstrates how to define an intent filter for supporting remote video playback using http, https, and Real Time Streaming Protocol (RTSP):

public final class SampleMediaRouteProvider extends MediaRouteProvider {    private static final ArrayList<IntentFilter> CONTROL_FILTERS_BASIC;    static {        IntentFilter videoPlayback = new IntentFilter();        videoPlayback.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);        videoPlayback.addAction(MediaControlIntent.ACTION_PLAY);        videoPlayback.addDataScheme("http");        videoPlayback.addDataScheme("https");        videoPlayback.addDataScheme("rtsp");        addDataTypeUnchecked(videoPlayback, "video/*");        CONTROL_FILTERS_BASIC = new ArrayList<IntentFilter>();        CONTROL_FILTERS_BASIC.add(videoPlayback);    }    ...    private static void addDataTypeUnchecked(IntentFilter filter, String type) {        try {            filter.addDataType(type);        } catch (MalformedMimeTypeException ex) {            throw new RuntimeException(ex);        }    }}

》The following code example demonstrates how to construct an intent filter for supporting basic media route playback controls:

public final class SampleMediaRouteProvider extends MediaRouteProvider {    private static final ArrayList<IntentFilter> CONTROL_FILTERS_BASIC;    static {        ...        IntentFilter playControls = new IntentFilter();        playControls.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);        playControls.addAction(MediaControlIntent.ACTION_SEEK);        playControls.addAction(MediaControlIntent.ACTION_GET_STATUS);        playControls.addAction(MediaControlIntent.ACTION_PAUSE);        playControls.addAction(MediaControlIntent.ACTION_RESUME);        playControls.addAction(MediaControlIntent.ACTION_STOP);        CONTROL_FILTERS_BASIC = new ArrayList<IntentFilter>();        CONTROL_FILTERS_BASIC.add(videoPlayback);        CONTROL_FILTERS_BASIC.add(playControls);    }    ...}
0 0