/** * Initialization of the Activity after it is first created. Must at least * call {@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. */ @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); // Get the media router service. mMediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE); // See assets/res/any/layout/presentation_with_media_router_activity.xml for this // view layout definition, which is being set here as // the content of our screen. setContentView(R.layout.presentation_with_media_router_activity); // Set up the surface view for visual interest. mSurfaceView = (GLSurfaceView)findViewById(R.id.surface_view); mSurfaceView.setRenderer(new CubeRenderer(false)); // Get a text view where we will show information about what's happening. mInfoTextView = (TextView)findViewById(R.id.info); }
@Override protected void onPause() { // Be sure to call the super class. super.onPause(); // Stop listening for changes to media routes. mMediaRouter.removeCallback(mMediaRouterCallback); // Pause rendering. mPaused = true; updateContents(); }
@Override protected void onResume() { // Be sure to call the super class. super.onResume(); // Listen for changes to media routes. mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback); // Update the presentation based on the currently selected route. mPaused = false; updatePresentation(); }
private void updateContents() { // Show either the content in the main activity or the content in the presentation // along with some descriptive text about what is happening. if (mPresentation != null) { mInfoTextView.setText(getResources().getString( R.string.presentation_with_media_router_now_playing_remotely, mPresentation.getDisplay().getName())); mSurfaceView.setVisibility(View.INVISIBLE); mSurfaceView.onPause(); if (mPaused) { mPresentation.getSurfaceView().onPause(); } else { mPresentation.getSurfaceView().onResume(); } } else { mInfoTextView.setText(getResources().getString( R.string.presentation_with_media_router_now_playing_locally, getWindowManager().getDefaultDisplay().getName())); mSurfaceView.setVisibility(View.VISIBLE); if (mPaused) { mSurfaceView.onPause(); } else { mSurfaceView.onResume(); } } }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Be sure to call the super class. super.onCreateOptionsMenu(menu); // Inflate the menu and configure the media router action provider. getMenuInflater().inflate(R.menu.presentation_with_media_router_menu, menu); MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route); MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider)mediaRouteMenuItem.getActionProvider(); mediaRouteActionProvider.setRouteTypes(MediaRouter.ROUTE_TYPE_LIVE_VIDEO); // Return true to show the menu. return true; }
private void updateContents() { // Show either the content in the main activity or the content in the presentation // along with some descriptive text about what is happening. if (mPresentation != null) { mInfoTextView.setText(getResources().getString( R.string.presentation_with_media_router_now_playing_remotely, mPresentation.getDisplay().getName())); mSurfaceView.setVisibility(View.INVISIBLE); mSurfaceView.onPause(); if (mPaused) { mPresentation.getSurfaceView().onPause(); } else { mPresentation.getSurfaceView().onResume(); } } else { mInfoTextView.setText(getResources().getString( R.string.presentation_with_media_router_now_playing_locally, getWindowManager().getDefaultDisplay().getName())); mSurfaceView.setVisibility(View.VISIBLE); if (mPaused) { mSurfaceView.onPause(); } else { mSurfaceView.onResume(); } } }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Be sure to call the super class. super.onCreateOptionsMenu(menu); // Inflate the menu and configure the media router action provider. getMenuInflater().inflate(R.menu.presentation_with_media_router_menu, menu); MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route); MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider)mediaRouteMenuItem.getActionProvider(); mediaRouteActionProvider.setRouteTypes(MediaRouter.ROUTE_TYPE_LIVE_VIDEO); // Return true to show the menu. return true; }
/** * Initialization of the Activity after it is first created. Must at least * call {@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. */ @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); // Get the media router service. mMediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE); // See assets/res/any/layout/presentation_with_media_router_activity.xml for this // view layout definition, which is being set here as // the content of our screen. setContentView(R.layout.presentation_with_media_router_activity); // Set up the surface view for visual interest. mSurfaceView = (GLSurfaceView)findViewById(R.id.surface_view); mSurfaceView.setRenderer(new CubeRenderer(false)); // Get a text view where we will show information about what's happening. mInfoTextView = (TextView)findViewById(R.id.info); }
@Override protected void onPause() { // Be sure to call the super class. super.onPause(); // Stop listening for changes to media routes. mMediaRouter.removeCallback(mMediaRouterCallback); // Pause rendering. mPaused = true; updateContents(); }
@Override protected void onResume() { // Be sure to call the super class. super.onResume(); // Listen for changes to media routes. mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback); // Update the presentation based on the currently selected route. mPaused = false; updatePresentation(); }
private void updatePresentation() { // Get the current route and its presentation display. MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute( MediaRouter.ROUTE_TYPE_LIVE_VIDEO); Display presentationDisplay = route != null ? route.getPresentationDisplay() : null; // Dismiss the current presentation if the display has changed. if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) { Log.i(TAG, "Dismissing presentation because the current route no longer " + "has a presentation display."); mPresentation.dismiss(); mPresentation = null; } // Show a new presentation if needed. if (mPresentation == null && presentationDisplay != null) { Log.i(TAG, "Showing presentation on display: " + presentationDisplay); mPresentation = new DemoPresentation(this, presentationDisplay); mPresentation.setOnDismissListener(mOnDismissListener); try { mPresentation.show(); } catch (WindowManager.InvalidDisplayException ex) { Log.w(TAG, "Couldn't show presentation! Display was removed in " + "the meantime.", ex); mPresentation = null; } } // Update the contents playing in this activity. updateContents(); }
private void updatePresentation() { // Get the current route and its presentation display. MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute( MediaRouter.ROUTE_TYPE_LIVE_VIDEO); Display presentationDisplay = route != null ? route.getPresentationDisplay() : null; // Dismiss the current presentation if the display has changed. if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) { Log.i(TAG, "Dismissing presentation because the current route no longer " + "has a presentation display."); mPresentation.dismiss(); mPresentation = null; } // Show a new presentation if needed. if (mPresentation == null && presentationDisplay != null) { Log.i(TAG, "Showing presentation on display: " + presentationDisplay); mPresentation = new DemoPresentation(this, presentationDisplay); mPresentation.setOnDismissListener(mOnDismissListener); try { mPresentation.show(); } catch (WindowManager.InvalidDisplayException ex) { Log.w(TAG, "Couldn't show presentation! Display was removed in " + "the meantime.", ex); mPresentation = null; } } // Update the contents playing in this activity. updateContents(); }