当前位置: 首页>>代码示例>>Java>>正文


Java MediaRouter类代码示例

本文整理汇总了Java中android.support.v7.media.MediaRouter的典型用法代码示例。如果您正苦于以下问题:Java MediaRouter类的具体用法?Java MediaRouter怎么用?Java MediaRouter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MediaRouter类属于android.support.v7.media包,在下文中一共展示了MediaRouter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupMediaRouter

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
private void setupMediaRouter() {
  mediaRouter = MediaRouter.getInstance(getApplicationContext());
  mediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
      CastMediaControlIntent.categoryForCast(getString(R.string.app_cast_id))).build();
  if (isRemoteDisplaying()) {
    this.castDevice = CastDevice.getFromBundle(mediaRouter.getSelectedRoute().getExtras());
  } else {
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      castDevice = extras.getParcelable(INTENT_EXTRA_CAST_DEVICE);
    }
  }

  mediaRouter.addCallback(mediaRouteSelector, mMediaRouterCallback,
      MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
 
开发者ID:ferranpons,项目名称:android-cast-remote-display-sample,代码行数:17,代码来源:MainActivity.java

示例2: onRouteSelected

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) {
    Log.d(TAG, "onRouteSelected: route=" + route);

    if (route.supportsControlCategory(
            MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)){
        // Stop local playback (if necessary)
        // ...

        // Save the new route
        mRoute = route;

        // Attach a new playback client
        mRemotePlaybackClient = new RemotePlaybackClient(getBaseContext(), mRoute);


        // Start remote playback (if necessary)
        // ...
    }
}
 
开发者ID:tgbMedia,项目名称:Android-app,代码行数:21,代码来源:VideoPlayerActivity.java

示例3: onRouteUnselected

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo route, int reason) {
    Log.d(TAG, "onRouteUnselected: route=" + route);

    if (route.supportsControlCategory(
            MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)){

        // Changed route: tear down previous client
        if (mRoute != null && mRemotePlaybackClient != null) {
            mRemotePlaybackClient.release();
            mRemotePlaybackClient = null;
        }

        // Save the new route
        mRoute = route;

        if (reason != MediaRouter.UNSELECT_REASON_ROUTE_CHANGED) {
            // Resume local playback  (if necessary)
            // ...
        }
    }
}
 
开发者ID:tgbMedia,项目名称:Android-app,代码行数:23,代码来源:VideoPlayerActivity.java

示例4: onRouteSelectedEvent

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
protected void onRouteSelectedEvent(MediaRouter router, RouteInfo route) {
    Log.d(TAG, "Selected route %s", route);
    if (!route.isSelected()) return;

    RecordCastAction.castPlayRequested();

    RecordCastAction.remotePlaybackDeviceSelected(
            RecordCastAction.DEVICE_TYPE_CAST_GENERIC);
    installBroadcastReceivers();

    if (getMediaStateListener() == null) {
        showCastError(route.getName());
        release();
        return;
    }

    if (route != getCurrentRoute()) {
        registerRoute(route);
        clearStreamState();
    }
    mPositionExtrapolator.clear();

    notifyRouteSelected(route);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:DefaultMediaRouteController.java

示例5: onRouteChanged

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteChanged(MediaRouter router, RouteInfo route) {
    // We only care about changes to the current route.
    if (!route.equals(getCurrentRoute())) return;
    // When there is no wifi connection, this condition becomes true.
    if (route.isConnecting()) {
        // We don't want to post the same Runnable twice.
        if (!mConnectionFailureNotifierQueued) {
            mConnectionFailureNotifierQueued = true;
            getHandler().postDelayed(mConnectionFailureNotifier,
                    CONNECTION_FAILURE_NOTIFICATION_DELAY_MS);
        }
    } else {
        // Only cancel the disconnect if we already posted the message. We can get into this
        // situation if we swap the current route provider (for example, switching to a YT
        // video while casting a non-YT video).
        if (mConnectionFailureNotifierQueued) {
            // We have reconnected, cancel the delayed disconnect.
            getHandler().removeCallbacks(mConnectionFailureNotifier);
            mConnectionFailureNotifierQueued = false;
        }
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:AbstractMediaRouteController.java

示例6: addMediaStateListener

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void addMediaStateListener(MediaStateListener listener) {
    if (mediaRouterInitializationFailed()) return;

    if (mAvailableRouteListeners.isEmpty()) {
        getMediaRouter().addCallback(mMediaRouteSelector, mDeviceDiscoveryCallback,
                MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
        Log.d(TAG, "Started device discovery");

        // Get the initial state
        mRoutesAvailable = getMediaRouter().isRouteAvailable(
                mMediaRouteSelector, MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE);
    }
    mAvailableRouteListeners.add(listener);
    // Send the current state to the listener.
    listener.onRouteAvailabilityChanged(mRoutesAvailable);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:18,代码来源:AbstractMediaRouteController.java

示例7: BaseCastManager

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
protected BaseCastManager(Context context, CastConfiguration castConfiguration) {
    mCastConfiguration = castConfiguration;
    mCapabilities = castConfiguration.getCapabilities();
    LogUtils.setDebug(isFeatureEnabled(CastConfiguration.FEATURE_DEBUGGING));

    sCclVersion = context.getString(R.string.ccl_version);
    mApplicationId = castConfiguration.getApplicationId();
    LOGD(TAG, "BaseCastManager is instantiated\nVersion: " + sCclVersion
            + "\nApplication ID: " + mApplicationId);
    mContext = context.getApplicationContext();
    mPreferenceAccessor = new PreferenceAccessor(mContext);
    mUiVisibilityHandler = new Handler(new UpdateUiVisibilityHandlerCallback());
    mPreferenceAccessor.saveStringToPreference(PREFS_KEY_APPLICATION_ID, mApplicationId);

    mMediaRouter = MediaRouter.getInstance(mContext);
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(mApplicationId)).build();

    mMediaRouterCallback = new CastMediaRouterCallback(this);
    mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
            MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:23,代码来源:BaseCastManager.java

示例8: onRouteSelected

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
    LOGD(TAG, "onRouteSelected: info=" + info);
    if (mCastManager.getReconnectionStatus()
            == BaseCastManager.RECONNECTION_STATUS_FINALIZED) {
        mCastManager.setReconnectionStatus(BaseCastManager.RECONNECTION_STATUS_INACTIVE);
        mCastManager.cancelReconnectionTask();
        return;
    }
    mCastManager.getPreferenceAccessor().saveStringToPreference(
            BaseCastManager.PREFS_KEY_ROUTE_ID, info.getId());
    CastDevice device = CastDevice.getFromBundle(info.getExtras());
    mCastManager.onDeviceSelected(device, info);
    LOGD(TAG, "onRouteSelected: mSelectedDevice=" + (device != null ? device.getFriendlyName()
            : "Null"));
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:17,代码来源:CastMediaRouterCallback.java

示例9: onRouteAdded

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteAdded(MediaRouter router, RouteInfo routeInfo) {
    if (!router.getDefaultRoute().equals(routeInfo)) {
        notifyRouteAvailabilityChangedIfNeeded(router);
        mCastManager.onCastDeviceDetected(routeInfo);
    }
    if (mCastManager.getReconnectionStatus()
            == BaseCastManager.RECONNECTION_STATUS_STARTED) {
        String routeId = mCastManager.getPreferenceAccessor().getStringFromPreference(
                BaseCastManager.PREFS_KEY_ROUTE_ID);
        if (routeInfo.getId().equals(routeId)) {
            // we found the route, so lets go with that
            LOGD(TAG, "onRouteAdded: Attempting to recover a session with info=" + routeInfo);
            mCastManager.setReconnectionStatus(BaseCastManager.RECONNECTION_STATUS_IN_PROGRESS);

            CastDevice device = CastDevice.getFromBundle(routeInfo.getExtras());
            LOGD(TAG, "onRouteAdded: Attempting to recover a session with device: "
                    + (device != null ? device.getFriendlyName() : "Null"));
            mCastManager.onDeviceSelected(device, routeInfo);
        }
    }
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:23,代码来源:CastMediaRouterCallback.java

示例10: onRouteRemoved

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteRemoved(final MediaRouter router, final RouteInfo route) {
    super.onRouteRemoved(router, route);

    CastDevice castDevice = CastDevice.getFromBundle(route.getExtras());
    String uuid = castDevice.getDeviceId();
    removedUUID.add(uuid);

    // Prevent immediate removing. There are some cases when service is removed and added
    // again after a second.
    if (removeRoutesTimer == null) {
        removeRoutesTimer = new Timer();
        removeRoutesTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                removeServices(route);
            }
        }, ROUTE_REMOVE_INTERVAL);
    }
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:21,代码来源:CastDiscoveryProvider.java

示例11: testStart

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Test
public void testStart() throws Exception {
    // TEST DESC.: start method should invoke MediaRouter removeCallback and addCalback
    // for stopping and starting services

    // when
    dp.start();

    // waiting for timer call
    Thread.sleep(200);
    Robolectric.runUiThreadTasksIncludingDelayedTasks();

    // then
    verify(mediaRouter).addCallback(any(MediaRouteSelector.class),
            any(MediaRouter.Callback.class), eq(MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY));
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:17,代码来源:CastDiscoveryProviderTest.java

示例12: startObservingMediaSinks

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
/**
 * Starts background monitoring for available media sinks compatible with the given
 * |sourceUrn|
 * @param sourceUrn a URL to use for filtering of the available media sinks
 */
@CalledByNative
public void startObservingMediaSinks(String sourceUrn) {
    if (mAndroidMediaRouter == null) return;

    MediaSource source = MediaSource.from(sourceUrn);
    if (source == null) return;

    String applicationId = source.getApplicationId();
    if (mDiscoveryCallbacks.containsKey(applicationId)) {
        mDiscoveryCallbacks.get(applicationId).addSourceUrn(sourceUrn);
        return;
    }

    DiscoveryCallback callback = new DiscoveryCallback(sourceUrn, this);
    mAndroidMediaRouter.addCallback(
            source.buildRouteSelector(),
            callback,
            MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
    mDiscoveryCallbacks.put(applicationId, callback);
}
 
开发者ID:Smalinuxer,项目名称:Vafrinn,代码行数:26,代码来源:ChromeMediaRouter.java

示例13: testReset

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Test
public void testReset() throws Exception {
    // Test desc.: reset method should stop discovering and clear found services

    // given
    dp.foundServices.put("service", mock(ServiceDescription.class));
    Assert.assertFalse(dp.foundServices.isEmpty());

    // when
    dp.reset();
    Robolectric.runUiThreadTasksIncludingDelayedTasks();

    // then
    verify(mediaRouter).removeCallback(any(MediaRouter.Callback.class));
    Assert.assertTrue(dp.foundServices.isEmpty());
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:17,代码来源:CastDiscoveryProviderTest.java

示例14: prepareCastButton

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
/**
 * sets up the Cast button and starts route discovery
 * @param castMenuItem the MenuItem holding a {@link CastScreenMediaRouteActionProvider}
 * @param appId id for a Remote Display Receiver application
 */
protected void prepareCastButton(MenuItem castMenuItem, String appId) {
    mSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(appId)
    ).build();

    mProvider = (CastScreenMediaRouteActionProvider)
            MenuItemCompat.getActionProvider(castMenuItem);
    mProvider.setRouteSelector(mSelector);
    mAppId = appId;

    mRouter = MediaRouter.getInstance(getApplicationContext());

    // Remove existing callback if present
    if(mCallback != null)
        mRouter.removeCallback(mCallback);

    mCallback = new MediaRouterCallback();
    mRouter.addCallback(mSelector, mCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
 
开发者ID:ankyl,项目名称:castscreen,代码行数:25,代码来源:CastScreenActivity.java

示例15: onRouteSelected

import android.support.v7.media.MediaRouter; //导入依赖的package包/类
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) {
    // start casting when the user selects a media route
    CastDevice device = CastDevice.getFromBundle(route.getExtras());
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    CastScreenService.start(getApplicationContext(),
        mAppId,
        metrics,
        mPermissionsResultCode,
        mPermissionsData,
        device,
        mRouter,
        CastScreenService.makeNotification(CastScreenActivity.this, device)
    );
}
 
开发者ID:ankyl,项目名称:castscreen,代码行数:18,代码来源:CastScreenActivity.java


注:本文中的android.support.v7.media.MediaRouter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。