android Media Router

来源:互联网 发布:amarra hifi mac 编辑:程序博客网 时间:2024/05/13 06:55

>As users connect their televisions, home theater systems and music players with wireless technologies, they want to be able to play content from Android apps on these larger, louder devices. Enabling this kind of playback can turn your one-device, one-user app into a shared experience that delights and inspires multiple users.

>The Android media router APIs are designed to enable media display and playback on these secondary devices:Remote Playback;Secondary Output

>the media router framework

>The media router APIs are provided as part of the Android Support Library version 18 and higher, in the v7-mediarouter support library. Specifically, you should use the classes in the android.support.v7.media package for media router functions. These APIs are compatible with devices running Android 2.1 (API level 7) and higher.

When creating a MediaRouteSelector object, use the MediaRouteSelector.Builder class to create the object and set the media playback categories (control categories), as shown in the following code sample:

public class MediaRouterPlaybackActivity extends ActionBarActivity {    private MediaRouteSelector mSelector;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        // Create a route selector for the type of routes your app supports.        mSelector = new MediaRouteSelector.Builder()                // These are the framework-supported intents                .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)                .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)                .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)                .build();    }}
An app that uses the media router framework must extend theMediaRouter.Callback object in order to receive messages when a media route is connected.

>Secondary devices can include televisions or wireless sound systems and can be attached through wireless protocols or wires, such as an HDMI cable. 

>

The following code sample shows a minimal implementation of a Presentation object, including aGLSurfaceView object.

public class SamplePresentation extends Presentation {    public SamplePresentation(Context outerContext, Display display) {        super(outerContext, display);    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // Notice that we get resources from the context of the Presentation        Resources resources = getContext().getResources();        // Inflate a layout.        setContentView(R.layout.presentation_with_media_router_content);        // Add presentation content here:        // Set up a surface view for visual interest        mSurfaceView = (GLSurfaceView)findViewById(R.id.surface_view);        mSurfaceView.setRenderer(new CubeRenderer(false));    }}
0 0
原创粉丝点击