Code example for MediaRouter

Methods: addCallback, getSelectedRoute

0
 
    @Override 
    public void onResume() { 
        super.onResume(); 
 
        mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
        updatePresentation(); 
    } 
 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present. 
        getMenuInflater().inflate(R.menu.video_presentation, menu);
        return true; 
    } 
     
    public void run() { 
        try { 
			Thread.sleep(500);
		} catch (InterruptedException e1) {
		} 
        int currentPosition = 0;
        int total = mVideoView.getDuration();
        mSeekBar.setMax(total);
        while (mVideoView != null && currentPosition < total) {
            try { 
                Thread.sleep(500);
                currentPosition = mVideoView.getCurrentPosition();
            } catch (InterruptedException e) {
                return; 
            } catch (Exception e) {
                return; 
            }             
            mSeekBar.setProgress(currentPosition);
        } 
    } 
    
    private void setMargins(int margin) {
    	FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mSurfaceRoot.getLayoutParams();
    	lp.bottomMargin = margin;
    	lp.topMargin = margin;
    	lp.leftMargin = margin;
    	lp.rightMargin = margin;
    	mSurfaceRoot.setLayoutParams(lp);
    } 
     
    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) {