android.media.MediaRouter Java Examples

The following examples show how to use android.media.MediaRouter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayManager.java    From libvlc-sdk-android with GNU General Public License v2.0 6 votes vote down vote up
public boolean setMediaRouterCallback() {
    if (mMediaRouter == null || mMediaRouterCallback != null) return false;
    mMediaRouterCallback = new MediaRouter.SimpleCallback() {
        @Override
        public void onRoutePresentationDisplayChanged(MediaRouter router, MediaRouter.RouteInfo info) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "onRoutePresentationDisplayChanged: info=" + info);
            final int newDisplayId = (info.getPresentationDisplay() != null) ? info.getPresentationDisplay().getDisplayId() : -1;
            if (newDisplayId == mPresentationId) return;
            mPresentationId = newDisplayId;
            if (newDisplayId == -1) removePresentation();
            else updateDisplayType();
        }
    };
    mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
    return true;
}
 
Example #2
Source File: DisplayManager.java    From libvlc-sdk-android with GNU General Public License v2.0 6 votes vote down vote up
private SecondaryDisplay createPresentation() {
    if (mMediaRouter == null) return null;
    final MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
    final Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;
    if (presentationDisplay != null) {
        if (BuildConfig.DEBUG)
            Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
        final SecondaryDisplay presentation = new SecondaryDisplay(mActivity, presentationDisplay);
        presentation.setOnDismissListener(mOnDismissListener);
        try {
            presentation.show();
            mPresentationId = presentationDisplay.getDisplayId();
            return presentation;
        } catch (WindowManager.InvalidDisplayException ex) {
            if (BuildConfig.DEBUG)
                Log.w(TAG, "Couldn't show presentation!  Display was removed in " + "the meantime.", ex);
            mPresentationId = -1;
        }
    } else if (BuildConfig.DEBUG) Log.i(TAG, "No secondary display detected");
    return null;
}
 
Example #3
Source File: MediaRouteButton.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the types of routes that will be shown in the media route chooser dialog
 * launched by this button.
 *
 * @param types The route types to match.
 */
public void setRouteTypes(int types) {
    if (mRouteTypes != types) {
        if (mAttachedToWindow && mRouteTypes != 0) {
            mRouter.removeCallback(mCallback);
        }

        mRouteTypes = types;

        if (mAttachedToWindow && types != 0) {
            mRouter.addCallback(types, mCallback,
                    MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
        }

        refreshRoute();
    }
}
 
Example #4
Source File: MainActivity.java    From android-BasicMediaRouter with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the ActionBar or options menu. The menu file defines an item for
 * the {@link android.app.MediaRouteActionProvider}, which is registered here for all
 * live video devices using {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO}.
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    getMenuInflater().inflate(R.menu.main, menu);

    // BEGIN_INCLUDE(MediaRouteActionProvider)
    // Configure the media router action provider
    MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route);
    MediaRouteActionProvider mediaRouteActionProvider =
            (MediaRouteActionProvider) mediaRouteMenuItem.getActionProvider();
    mediaRouteActionProvider.setRouteTypes(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
    // BEGIN_INCLUDE(MediaRouteActionProvider)

    return true;
}
 
Example #5
Source File: MainActivity.java    From android-BasicMediaRouter with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    // BEGIN_INCLUDE(addCallback)
    // Register a callback for all events related to live video devices
    mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
    // END_INCLUDE(addCallback)

    // Show the 'Not connected' status message
    mButton.setEnabled(false);
    mTextStatus.setText(R.string.secondary_notconnected);

    // Update the displays based on the currently active routes
    updatePresentation();
}
 
Example #6
Source File: MediaRouteButton.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public MediaRouteButton(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mRouter = (MediaRouter)context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mCallback = new MediaRouterCallback();

    final TypedArray a = context.obtainStyledAttributes(attrs,
            com.android.internal.R.styleable.MediaRouteButton, defStyleAttr, defStyleRes);
    setRemoteIndicatorDrawable(a.getDrawable(
            com.android.internal.R.styleable.MediaRouteButton_externalRouteEnabledDrawable));
    mMinWidth = a.getDimensionPixelSize(
            com.android.internal.R.styleable.MediaRouteButton_minWidth, 0);
    mMinHeight = a.getDimensionPixelSize(
            com.android.internal.R.styleable.MediaRouteButton_minHeight, 0);
    final int routeTypes = a.getInteger(
            com.android.internal.R.styleable.MediaRouteButton_mediaRouteTypes,
            MediaRouter.ROUTE_TYPE_LIVE_AUDIO);
    a.recycle();

    setClickable(true);

    setRouteTypes(routeTypes);
}
 
Example #7
Source File: MainActivity.java    From android-BasicMediaRouter with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.sample_main);
    mTextStatus = (TextView) findViewById(R.id.textStatus);

    // get the list of background colors
    mColors = getResources().getIntArray(R.array.androidcolors);

    // Enable clicks on the 'change color' button
    mButton = (Button) findViewById(R.id.button1);
    mButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showNextColor();
        }
    });

    // BEGIN_INCLUDE(getMediaRouter)
    // Get the MediaRouter service
    mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
    // END_INCLUDE(getMediaRouter)
}
 
Example #8
Source File: JukeboxRouteProvider.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
private void broadcastDescriptor() {
	// Create intents
	IntentFilter routeIntentFilter = new IntentFilter();
	routeIntentFilter.addCategory(CATEGORY_JUKEBOX_ROUTE);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_START_SESSION);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_GET_SESSION_STATUS);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_END_SESSION);

	// Create route descriptor
	MediaRouteDescriptor.Builder routeBuilder = new MediaRouteDescriptor.Builder("Jukebox Route", "Subsonic Jukebox");
	routeBuilder.addControlFilter(routeIntentFilter)
			.setPlaybackStream(AudioManager.STREAM_MUSIC)
			.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
			.setDescription("Subsonic Jukebox")
			.setVolume(controller == null ? 5 : (int) (controller.getVolume() * 10))
			.setVolumeMax(MAX_VOLUME)
			.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);

	// Create descriptor
	MediaRouteProviderDescriptor.Builder providerBuilder = new MediaRouteProviderDescriptor.Builder();
	providerBuilder.addRoute(routeBuilder.build());
	setDescriptor(providerBuilder.build());
}
 
Example #9
Source File: MediaRouterService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void setDiscoveryRequestLocked(IMediaRouterClient client,
        int routeTypes, boolean activeScan) {
    final IBinder binder = client.asBinder();
    ClientRecord clientRecord = mAllClientRecords.get(binder);
    if (clientRecord != null) {
        // Only let the system discover remote display routes for now.
        if (!clientRecord.mTrusted) {
            routeTypes &= ~MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
        }

        if (clientRecord.mRouteTypes != routeTypes
                || clientRecord.mActiveScan != activeScan) {
            if (DEBUG) {
                Slog.d(TAG, clientRecord + ": Set discovery request, routeTypes=0x"
                        + Integer.toHexString(routeTypes) + ", activeScan=" + activeScan);
            }
            clientRecord.mRouteTypes = routeTypes;
            clientRecord.mActiveScan = activeScan;
            clientRecord.mUserRecord.mHandler.sendEmptyMessage(
                    UserHandler.MSG_UPDATE_DISCOVERY_REQUEST);
        }
    }
}
 
Example #10
Source File: MediaRouterService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static int getConnectionPhase(int status) {
    switch (status) {
        case MediaRouter.RouteInfo.STATUS_NONE:
        case MediaRouter.RouteInfo.STATUS_CONNECTED:
            return PHASE_CONNECTED;
        case MediaRouter.RouteInfo.STATUS_CONNECTING:
            return PHASE_CONNECTING;
        case MediaRouter.RouteInfo.STATUS_SCANNING:
        case MediaRouter.RouteInfo.STATUS_AVAILABLE:
            return PHASE_NOT_CONNECTED;
        case MediaRouter.RouteInfo.STATUS_NOT_AVAILABLE:
        case MediaRouter.RouteInfo.STATUS_IN_USE:
        default:
            return PHASE_NOT_AVAILABLE;
    }
}
 
Example #11
Source File: MediaRouteActionProvider.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the types of routes that will be shown in the media route chooser dialog
 * launched by this button.
 *
 * @param types The route types to match.
 */
public void setRouteTypes(int types) {
    if (mRouteTypes != types) {
        // FIXME: We currently have no way of knowing whether the action provider
        // is still needed by the UI.  Unfortunately this means the action provider
        // may leak callbacks until garbage collection occurs.  This may result in
        // media route providers doing more work than necessary in the short term
        // while trying to discover routes that are no longer of interest to the
        // application.  To solve this problem, the action provider will need some
        // indication from the framework that it is being destroyed.
        if (mRouteTypes != 0) {
            mRouter.removeCallback(mCallback);
        }
        mRouteTypes = types;
        if (types != 0) {
            mRouter.addCallback(types, mCallback,
                    MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
        }
        refreshRoute();

        if (mButton != null) {
            mButton.setRouteTypes(mRouteTypes);
        }
    }
}
 
Example #12
Source File: MediaRouterService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static int computeStatusCode(RemoteDisplayInfo descriptor) {
    switch (descriptor.status) {
        case RemoteDisplayInfo.STATUS_NOT_AVAILABLE:
            return MediaRouter.RouteInfo.STATUS_NOT_AVAILABLE;
        case RemoteDisplayInfo.STATUS_AVAILABLE:
            return MediaRouter.RouteInfo.STATUS_AVAILABLE;
        case RemoteDisplayInfo.STATUS_IN_USE:
            return MediaRouter.RouteInfo.STATUS_IN_USE;
        case RemoteDisplayInfo.STATUS_CONNECTING:
            return MediaRouter.RouteInfo.STATUS_CONNECTING;
        case RemoteDisplayInfo.STATUS_CONNECTED:
            return MediaRouter.RouteInfo.STATUS_CONNECTED;
        default:
            return MediaRouter.RouteInfo.STATUS_NONE;
    }
}
 
Example #13
Source File: DLNARouteProvider.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onControlRequest(Intent intent, android.support.v7.media.MediaRouter.ControlRequestCallback callback) {
	if (intent.hasCategory(CATEGORY_DLNA)) {
		return true;
	} else {
		return false;
	}
}
 
Example #14
Source File: MediaProjectionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    publishBinderService(Context.MEDIA_PROJECTION_SERVICE, new BinderService(),
            false /*allowIsolated*/);
    mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY, mMediaRouterCallback,
            MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
}
 
Example #15
Source File: VolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteSelected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
    LOGD("MediaRouteListener", "onRouteSelected(" + type + ", " + info.getName() + ")");
    mCurrentRouteInfo = info;
    mCurrentRouteType = type;
    refreshRoute();
}
 
Example #16
Source File: MediaProjectionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteSelected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
    synchronized (mLock) {
        if ((type & MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY) != 0) {
            mMediaRouteInfo = info;
            if (mProjectionGrant != null) {
                mProjectionGrant.stop();
            }
        }
    }
}
 
Example #17
Source File: MediaProjectionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public MediaProjectionManagerService(Context context) {
    super(context);
    mContext = context;
    mDeathEaters = new ArrayMap<IBinder, IBinder.DeathRecipient>();
    mCallbackDelegate = new CallbackDelegate();
    mAppOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
    mMediaRouter = (MediaRouter) mContext.getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mMediaRouterCallback = new MediaRouterCallback();
    Watchdog.getInstance().addMonitor(this);
}
 
Example #18
Source File: VolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteUnselected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
    LOGD("MediaRouteListener", "onRouteUnselected(" + type + ", " + info.getName() + ")");
    mCurrentRouteInfo = null;
    mCurrentRouteType = type;
    refreshRoute();
}
 
Example #19
Source File: MediaRouterService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static int computeVolumeHandling(RemoteDisplayInfo descriptor) {
    final int volumeHandling = descriptor.volumeHandling;
    switch (volumeHandling) {
        case RemoteDisplayInfo.PLAYBACK_VOLUME_VARIABLE:
            return MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE;
        case RemoteDisplayInfo.PLAYBACK_VOLUME_FIXED:
        default:
            return MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
    }
}
 
Example #20
Source File: MediaRouteButton.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void refreshRoute() {
    final MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
    final boolean isRemote = !route.isDefault() && route.matchesTypes(mRouteTypes);
    final boolean isConnecting = isRemote && route.isConnecting();
    boolean needsRefresh = false;
    if (mRemoteActive != isRemote) {
        mRemoteActive = isRemote;
        needsRefresh = true;
    }
    if (mIsConnecting != isConnecting) {
        mIsConnecting = isConnecting;
        needsRefresh = true;
    }

    if (needsRefresh) {
        refreshDrawableState();
    }
    if (mAttachedToWindow) {
        setEnabled(mRouter.isRouteAvailable(mRouteTypes,
                MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE));
    }
    if (mRemoteIndicator != null
            && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) {
        AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent();
        if (mAttachedToWindow) {
            if ((needsRefresh || isConnecting) && !curDrawable.isRunning()) {
                curDrawable.start();
            }
        } else if (isRemote && !isConnecting) {
            // When the route is already connected before the view is attached, show the last
            // frame of the connected animation immediately.
            if (curDrawable.isRunning()) {
                curDrawable.stop();
            }
            curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1);
        }
    }
}
 
Example #21
Source File: MediaRouteButton.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    mAttachedToWindow = true;
    if (mRouteTypes != 0) {
        mRouter.addCallback(mRouteTypes, mCallback,
                MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
    }
    refreshRoute();
}
 
Example #22
Source File: DLNARouteProvider.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
private void broadcastDescriptors() {
	// Create intents
	IntentFilter routeIntentFilter = new IntentFilter();
	routeIntentFilter.addCategory(CATEGORY_DLNA);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_START_SESSION);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_GET_SESSION_STATUS);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_END_SESSION);

	// Create descriptor
	MediaRouteProviderDescriptor.Builder providerBuilder = new MediaRouteProviderDescriptor.Builder();

	// Create route descriptor
	for(Map.Entry<String, DLNADevice> deviceEntry: devices.entrySet()) {
		DLNADevice device = deviceEntry.getValue();

		int volume;
		if(device.volumeMax <= 0) {
			volume = 5;
		} else {
			int increments = (int) Math.ceil(device.volumeMax / 10.0);
			volume = controller == null ? device.volume : (int) controller.getVolume();
			volume = volume / increments;
		}

		MediaRouteDescriptor.Builder routeBuilder = new MediaRouteDescriptor.Builder(device.id, device.name);
		routeBuilder.addControlFilter(routeIntentFilter)
				.setPlaybackStream(AudioManager.STREAM_MUSIC)
				.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
				.setDescription(device.description)
				.setVolume(volume)
				.setVolumeMax(10)
				.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);
		providerBuilder.addRoute(routeBuilder.build());
	}

	setDescriptor(providerBuilder.build());
}
 
Example #23
Source File: JukeboxRouteProvider.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onControlRequest(Intent intent, android.support.v7.media.MediaRouter.ControlRequestCallback callback) {
	if (intent.hasCategory(CATEGORY_JUKEBOX_ROUTE)) {
		return true;
	} else {
		return false;
	}
}
 
Example #24
Source File: MediaRouteActionProvider.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public MediaRouteActionProvider(Context context) {
    super(context);

    mContext = context;
    mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mCallback = new MediaRouterCallback(this);

    // Start with live audio by default.
    // TODO Update this when new route types are added; segment by API level
    // when different route types were added.
    setRouteTypes(MediaRouter.ROUTE_TYPE_LIVE_AUDIO);
}
 
Example #25
Source File: VolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteUnselected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
    LOGD("MediaRouteListener", "onRouteUnselected(" + type + ", " + info.getName() + ")");
    mCurrentRouteInfo = null;
    mCurrentRouteType = type;
    refreshRoute();
}
 
Example #26
Source File: VolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public void onRouteSelected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
    LOGD("MediaRouteListener", "onRouteSelected(" + type + ", " + info.getName() + ")");
    mCurrentRouteInfo = info;
    mCurrentRouteType = type;
    refreshRoute();
}
 
Example #27
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void createPresentation() {
    if (mMediaRouter == null || mEnableCloneMode)
        return;

    // 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;

    if (presentationDisplay != null) {
        // Show a new presentation if possible.
        Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
        mPresentation = new SecondaryDisplay(this, LibVLC(), presentationDisplay);
        mPresentation.setOnDismissListener(mOnDismissListener);
        try {
            mPresentation.show();
            mPresentationDisplayId = presentationDisplay.getDisplayId();
        } catch (WindowManager.InvalidDisplayException ex) {
            Log.w(TAG, "Couldn't show presentation!  Display was removed in "
                    + "the meantime.", ex);
            mPresentation = null;
        }
    } else
        Log.i(TAG, "No secondary display detected");
}
 
Example #28
Source File: MediaRouteActionProvider.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void refreshRoute(MediaRouter router) {
    MediaRouteActionProvider provider = mProviderWeak.get();
    if (provider != null) {
        provider.refreshRoute();
    } else {
        router.removeCallback(this);
    }
}
 
Example #29
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Add or remove MediaRouter callbacks. This is provided for version targeting.
 *
 * @param add true to add, false to remove
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void mediaRouterAddCallback(boolean add) {
    if(!AndroidUtil.isJellyBeanMR1OrLater() || mMediaRouter == null) return;

    if(add)
        mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
    else
        mMediaRouter.removeCallback(mMediaRouterCallback);
}
 
Example #30
Source File: DisplayManager.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
public DisplayManager(@NonNull Activity activity, @Nullable LiveData<RendererItem> selectedRender, boolean textureView, boolean cloneMode, boolean benchmark) {
    mActivity = activity;
    mSelectedRenderer = selectedRender;
    mMediaRouter = (MediaRouter) activity.getApplicationContext().getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mTextureView = textureView;
    mPresentation = !cloneMode && !benchmark && selectedRender != null && selectedRender.getValue() == null ? createPresentation() : null;
    if (mSelectedRenderer != null) {
        mRendererItem = mSelectedRenderer.getValue();
        mSelectedRenderer.observeForever(mRendererObs);
    }
    mDisplayType = benchmark ? DisplayType.PRIMARY : getCurrentType();
}