本文整理汇总了Java中android.support.v7.media.MediaRouter.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java MediaRouter.getInstance方法的具体用法?Java MediaRouter.getInstance怎么用?Java MediaRouter.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.media.MediaRouter
的用法示例。
在下文中一共展示了MediaRouter.getInstance方法的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);
}
示例2: 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);
}
示例3: 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);
}
示例4: onDismiss
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (mCancelled) {
if (mPlayer != null) mPlayer.onRouteDialogCancelled();
return;
}
if (mController != null) {
MediaRouter router = MediaRouter.getInstance(mContext);
mController.onRouteSelected(mPlayer, router, router.getSelectedRoute());
}
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:15,代码来源:MediaRouteChooserDialogFactory.java
示例5: AbstractMediaRouteController
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
protected AbstractMediaRouteController() {
mContext = ContextUtils.getApplicationContext();
assert (getContext() != null);
mHandler = new Handler();
mMediaRouteSelector = buildMediaRouteSelector();
MediaRouter mediaRouter;
try {
// Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
// so getting the MediaRouter instance will throw an exception.
mediaRouter = MediaRouter.getInstance(getContext());
} catch (NoSuchMethodError e) {
Log.e(TAG, "Can't get an instance of MediaRouter, casting is not supported."
+ " Are you still on JB (JVP15S)?");
mediaRouter = null;
}
mMediaRouter = mediaRouter;
mAvailableRouteListeners = new HashSet<MediaStateListener>();
// TODO(aberent): I am unclear why this is accessed from multiple threads, but
// if I make it a HashSet then it gets ConcurrentModificationExceptions on some
// types of disconnect. Investigate and fix.
mUiListeners = new CopyOnWriteArraySet<UiListener>();
mDeviceDiscoveryCallback = new DeviceDiscoveryCallback();
mDeviceSelectionCallback = new DeviceSelectionCallback();
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:31,代码来源:AbstractMediaRouteController.java
示例6: onCreate
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CallbackThreadHandler.init(new MainThreadWrapper());
if(BuildConfig.DEBUG) {
//adb shell setprop log.tag.ocast.driver.link VERBOSE
//adb shell setprop log.tag.ocast.driver.link OFF
try {
InputStream ins = getResources().openRawResource(R.raw.logging);
DebugHelper.initLogging(ins);
} catch (IOException e) {
Log.e(TAG, "could not initialize logger");
}
}
ActivityMainBinding binding = DataBindingUtil.setContentView(this,R.layout.activity_main );
viewmodel = new ViewModel(getString(R.string.webapp_id), this);
binding.setViewmodel(viewmodel);
setSupportActionBar(binding.myToolbar);
binding.buttonStart.setOnClickListener(v->startWebApp());
binding.buttonStop.setOnClickListener(v-> stopWebApp());
binding.buttonJoin.setOnClickListener(v-> joinWebApp());
binding.buttonPlayMedia.setOnClickListener(v -> playMedia());
binding.buttonPauseMedia.setOnClickListener(v-> pauseMedia());
binding.buttonStopMedia.setOnClickListener(v -> stopMedia());
OCastRouteHelper.addMediaRouteProvider(getApplicationContext(), Arrays.asList(ReferenceDriver.SEARCH_TARGET));
DeviceManager.registerDriver("Orange SA", new ReferenceDriver.ReferenceFactory());
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(OCastMediaRouteProvider.CATEGORY_OCAST)
.build();
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallBack, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
示例7: addMediaRouteProvider
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
/**
* register the {@link org.ocast.mediaroute.OCastMediaRouteProvider OCastMediaRouteProvider}
* on the MediaRouter
* @param context
* @param searchTargets a list of search targets to be discovered
*/
public static void addMediaRouteProvider(Context context, List<String> searchTargets) {
if(sOCastProvider == null) {
MediaRouter mediaRouter = MediaRouter.getInstance(context.getApplicationContext());
sOCastProvider = new OCastMediaRouteProvider(context.getApplicationContext(), searchTargets);
mediaRouter.addProvider(sOCastProvider);
}
}
示例8: setUpMediaRouter
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
private void setUpMediaRouter() {
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(
CastMediaControlIntent.categoryForCast(
getResources().getString(R.string.app_id)
)
)
.build();
mMediaRouterCallback = new PinCastMediaRouterCallback();
}
示例9: LockScreenTransportControlV16
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
LockScreenTransportControlV16(Context context) {
mDebug = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CAST_DEBUG_LOGS);
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mMediaEventReceiver = new ComponentName(context.getPackageName(),
MediaButtonIntentReceiver.class.getName());
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mMediaEventReceiver);
mMediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0,
mediaButtonIntent, 0);
mAudioFocusListener = new AudioFocusListener();
mMediaRouter = MediaRouter.getInstance(context);
}
示例10: AbstractMediaRouteController
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
/**
* Sole constructor
*/
protected AbstractMediaRouteController() {
mDebug = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CAST_DEBUG_LOGS);
mContext = ApplicationStatus.getApplicationContext();
assert (getContext() != null);
mHandler = new Handler();
mMediaRouteSelector = buildMediaRouteSelector();
MediaRouter mediaRouter;
try {
// Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
// so getting the MediaRouter instance will throw an exception.
mediaRouter = MediaRouter.getInstance(getContext());
} catch (NoSuchMethodError e) {
Log.e(TAG, "Can't get an instance of MediaRouter, casting is not supported."
+ " Are you still on JB (JVP15S)?");
mediaRouter = null;
}
mMediaRouter = mediaRouter;
mAvailableRouteListeners = new HashSet<MediaStateListener>();
// TODO(aberent): I am unclear why this is accessed from multiple threads, but
// if I make it a HashSet then it gets ConcurrentModificationExceptions on some
// types of disconnect. Investigate and fix.
mUiListeners = new CopyOnWriteArraySet<UiListener>();
mDeviceDiscoveryCallback = new DeviceDiscoveryCallback();
mDeviceSelectionCallback = new DeviceSelectionCallback();
}
示例11: ChromeMediaRouterDialogController
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
private ChromeMediaRouterDialogController(long nativeDialogController, Context context) {
mNativeDialogController = nativeDialogController;
MediaRouter androidMediaRouter = null;
try {
// Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
// so getting the MediaRouter instance will throw an exception.
androidMediaRouter = MediaRouter.getInstance(context);
} catch (NoSuchMethodError e) {
androidMediaRouter = null;
}
mAndroidMediaRouter = androidMediaRouter;
}
示例12: getAndroidMediaRouter
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
@Nullable
private MediaRouter getAndroidMediaRouter(Context applicationContext) {
try {
// Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
// so getting the MediaRouter instance will throw an exception.
return MediaRouter.getInstance(applicationContext);
} catch (NoSuchMethodError e) {
return null;
}
}
示例13: onCreate
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
//Dagger
((TgbApp) getApplication()).getAppComponent().inject(this);
//Butterknife
ButterKnife.bind(this);
// Get the media router service.
mMediaRouter = MediaRouter.getInstance(this);
//Elements
toolbar = playerView.findViewById(R.id.toolbar);
backdrop = playerView.findViewById(R.id.backdrop);
playerPoster = playerView.findViewById(R.id.poster);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setSupportActionBar(toolbar);
//ExoPlayer
mainHandler = new Handler();
dataSourceFactory = ((TgbApp) getApplication()).buildHttpDataSourceFactory(BANDWIDTH_METER);
// 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_REMOTE_PLAYBACK)
.build();
//Create new player instance
player = ExoPlayerFactory.newSimpleInstance(
new DefaultRenderersFactory(this),
new DefaultTrackSelector(), new DefaultLoadControl());
//Associate player to view
playerView.setPlayer(player);
//Player settings
player.addListener(this);
player.setPlayWhenReady(true);
playerView.showController();
playerView.setControllerHideOnTouch(false);
initializeUI();
}
示例14: onCreate
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
public void onCreate() {
super.onCreate();
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
mMediaRouterCallback = new MediaRouter.Callback (){
public void onRoutePresentationDisplayChanged(MediaRouter router, MediaRouter.RouteInfo route) {
Log.d(TAG,"onRoutePresentationDisplayChanged ");
if(CastPlayerService.sCastPlayerService !=null&&route.getPresentationDisplay()!=null)
CastPlayerService.sCastPlayerService.createDisplayContext(route.getPresentationDisplay());
}
@Override
public void onRouteSelected(MediaRouter router, final MediaRouter.RouteInfo info) {
final CastDevice device = CastDevice.getFromBundle(info.getExtras());
if(device==null)
return;
ArchosVideoCastManager.getInstance().setSelectedRoute(info);
}
@Override
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo info) {
ArchosVideoCastManager.getInstance().setSelectedRoute(info);
}
};
sCastPlayerService = this;
mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mSubtitleSizeDefault = getResources().getInteger(R.integer.player_pref_subtitle_size_default);
mSubtitleColorDefault = Color.parseColor(getResources().getString(R.string.subtitle_color_default));
mSubtitleVPosDefault = getResources().getInteger(R.integer.player_pref_subtitle_vpos_default);
Log.d(TAG,"onCreate");
bindService(new Intent(this, PlayerService.class), mPlayerServiceConnection, BIND_AUTO_CREATE);
if(PlayerService.sPlayerService!=null)
onFirstScreenPresentationCreatedAndServiceConnected();
mWindowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
AppState.addOnForeGroundListener(this);
IntentFilter filter = new IntentFilter();
filter.addAction("DISPLAY_FLOATING_PLAYER");
filter.addAction(PlayerService.PLAY_INTENT);
filter.addAction(PlayerService.PAUSE_INTENT);
filter.addAction(PlayerService.EXIT_INTENT);
filter.addAction(PlayerService.FULLSCREEN_INTENT);
}
示例15: ArchosVideoCastManager
import android.support.v7.media.MediaRouter; //导入方法依赖的package包/类
public ArchosVideoCastManager(Context context){
mMiniControllers = new ArrayList();
mContext = context;
reset();
mArchosCastManagerListeners = new ArrayList<>();
if(!isCastAvailable()) {
mCastManager = null;
mMediaRouter = null;
mMediaRouteSelector = null;
return;
}
mCastManager = VideoCastManager.getInstance();
mCastManager.addMiniController(this);//this will set mOnMiniControllerChangedListener
mCastManager.addVideoCastConsumer(mCastConsumer);
mCastManager.addTracksSelectedListener(new OnTracksSelectedListener() {
@Override
public void onTracksSelected(List<MediaTrack> tracks) {
ArchosVideoCastManager.getInstance().setSelectedTracks(tracks);
}
});
mRouteSelectorCallback = new MediaRouter.Callback(){
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) {
setSelectedRoute(route);
if(CastDebug.DBG){
CastDebug.log("onRouteSelected null ? "+(route==null));
}
}
public void onRouteRemoved(MediaRouter router, MediaRouter.RouteInfo route) {
Log.d(TAG, "route removed");
if(CastDebug.DBG){
CastDebug.log("onRouteRemoved "+route.getName());
}
//sometimes onRouteRemoved is called when doing screencast, even when it still works
}
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo route, int reason) {
Log.d(TAG, "onRouteUnselected "+mDoNotUnselectRoute);
if(CastDebug.DBG){
CastDebug.log("onRouteUnselected mDoNotUnselectRoute ?"+(mDoNotUnselectRoute));
}
if(mDoNotUnselectRoute){
mDoNotUnselectRoute = false;
}
else {
if(CastDebug.DBG){
//check if deco is normal
if(route!=null&&route.getExtras()!=null) {
CastDevice device = CastDevice.getFromBundle(route.getExtras());
if (device.getFriendlyName() != null && device.getFriendlyName().equals(getDeviceName())) {
CastDebug.log("WARNING: current device removed : " + getDeviceName());
}
}
}
setSelectedRoute(null);
reset();
refreshCastListeners();
}
}
};
mMediaRouter = MediaRouter.getInstance(mContext);
mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
CastMediaControlIntent.categoryForCast(mContext.getString(R.string.app_id))).build();
mMediaRouter.addCallback(mMediaRouteSelector, mRouteSelectorCallback,
MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}