本文整理汇总了Java中android.media.session.MediaSessionManager类的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionManager类的具体用法?Java MediaSessionManager怎么用?Java MediaSessionManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaSessionManager类属于android.media.session包,在下文中一共展示了MediaSessionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@Override
public void onCreate(){
registerReceiver(button,new IntentFilter(MEDIA_ACTION));
mediaSessionManager = (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
try {
mediaSessionManager.addOnActiveSessionsChangedListener(sessionListener, componentName);
List<MediaController> controllers = mediaSessionManager.getActiveSessions(componentName);
mediaController = pickController(controllers);
if (mediaController != null) {
mediaController.registerCallback(callback);
meta = mediaController.getMetadata();
updateMetadata();
}
online = true;
} catch (SecurityException e) {
}
}
示例2: FindMediaSessionAppsTask
import android.media.session.MediaSessionManager; //导入依赖的package包/类
private FindMediaSessionAppsTask(MediaSessionManager mediaSessionManager,
ComponentName listenerComponent,
PackageManager packageManager,
AppListUpdatedCallback callback) {
super(callback);
mMediaSessionManager = mediaSessionManager;
mListenerComponent = listenerComponent;
mPackageManager = packageManager;
}
示例3: onDestroy
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@Override
public void onDestroy() {
unregisterUpdateBroadcastReceiver();
threadCancelled = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && networkCallback != null)
try {
((ConnectivityManager) getActivity().getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE)).unregisterNetworkCallback(networkCallback);
} catch (IllegalArgumentException ignored) {
}
if (Build.VERSION.SDK_INT >= 21 && sessionListener != null) {
((MediaSessionManager) getActivity().getSystemService(Context.MEDIA_SESSION_SERVICE))
.removeOnActiveSessionsChangedListener((OnActiveSessionsChangedListener) sessionListener);
}
super.onDestroy();
RefWatcher refWatcher = App.getRefWatcher(getActivity());
refWatcher.watch(this);
}
示例4: answerUsingMediaServer
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void answerUsingMediaServer()
{
Timber.d("Answering using media server method...");
MediaSessionManager mediaSessionManager = (MediaSessionManager) getCallModule().getService().getSystemService(Context.MEDIA_SESSION_SERVICE);
try {
List<MediaController> mediaControllerList = mediaSessionManager.getActiveSessions
(new ComponentName(getCallModule().getService(), JellybeanNotificationListener.class));
for (MediaController m : mediaControllerList) {
if ("com.android.server.telecom".equals(m.getPackageName())) {
Timber.d("Found telephony media controller!");
m.dispatchMediaButtonEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
break;
}
}
} catch (SecurityException e) {
Timber.e("Notification service not running!");
}
}
示例5: onCreate
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@Override
public void onCreate(){
registerReceiver(button,new IntentFilter(StandardWidget.WIDGET_ACTION));
mediaSessionManager = (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
mediaSessionManager.addOnActiveSessionsChangedListener(sessionListener, componentName);
List<MediaController> controllers = mediaSessionManager.getActiveSessions(componentName);
mediaController = pickController(controllers);
if(mediaController!=null) {
mediaController.registerCallback(callback);
meta = mediaController.getMetadata();
updateMetadata();
}
online = true;
sendBroadcast(new Intent(StandardWidget.WIDGET_UPDATE));
}
示例6: sync
import android.media.session.MediaSessionManager; //导入依赖的package包/类
public void sync() {
mDevice.enableNotify(mediaCommandsCharac, commandsListener);
try {
mMediaSessionManager = (MediaSessionManager) mCtx.getSystemService(Context.MEDIA_SESSION_SERVICE);
List<MediaController> controllers = mMediaSessionManager.getActiveSessions(new ComponentName(mCtx, NLService.class));
onActiveSessionsChanged(controllers);
mMediaSessionManager.addOnActiveSessionsChangedListener(this, new ComponentName(mCtx, NLService.class));
} catch (SecurityException e) {
Log.w("MediaService", "No Notification Access");
}
}
示例7: onCreate
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@Override
public void onCreate() {
ScroballApplication application = (ScroballApplication) getApplication();
sharedPreferences = application.getSharedPreferences();
ConnectivityManager connectivityManager =
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
ScroballDB scroballDB = application.getScroballDB();
ScrobbleNotificationManager scrobbleNotificationManager =
new ScrobbleNotificationManager(this, sharedPreferences);
LastfmClient lastfmClient = application.getLastfmClient();
Scrobbler scrobbler =
new Scrobbler(lastfmClient, scrobbleNotificationManager, scroballDB, connectivityManager);
playbackTracker = new PlaybackTracker(scrobbleNotificationManager, scrobbler);
Log.d(TAG, "NotificationListenerService started");
MediaSessionManager mediaSessionManager =
(MediaSessionManager)
getApplicationContext().getSystemService(Context.MEDIA_SESSION_SERVICE);
ComponentName componentName = new ComponentName(this, this.getClass());
mediaSessionManager.addOnActiveSessionsChangedListener(this, componentName);
NetworkStateReceiver networkStateReceiver = new NetworkStateReceiver(scrobbler);
IntentFilter filter = new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
this.registerReceiver(networkStateReceiver, filter);
// Trigger change event with existing set of sessions.
List<MediaController> initialSessions = mediaSessionManager.getActiveSessions(componentName);
onActiveSessionsChanged(initialSessions);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
示例8: RemoteControlLollipop
import android.media.session.MediaSessionManager; //导入依赖的package包/类
protected RemoteControlLollipop(Context context, Class<? extends NotificationListenerService> clazz) {
super(context);
mControllerService = new ComponentName(context, clazz);
mControllers = new ConcurrentHashMap<>();
mMediaSessionManager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
mMediaSessionManager.addOnActiveSessionsChangedListener(this, mControllerService);
mRegistered = true;
}
示例9: onStart
import android.media.session.MediaSessionManager; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onStart(Object... objects) {
super.onStart();
// Init a new thread.
mThread = new T(this);
mThread.setPriority(Thread.MIN_PRIORITY);
mThread.start();
// Media session manager leaks/holds the context for too long.
// Don't let it to leak the activity, better lak the whole app.
final Context context = mContext.getApplicationContext();
mMediaSessionManager = (MediaSessionManager) context
.getSystemService(Context.MEDIA_SESSION_SERVICE);
try {
mMediaSessionManager.addOnActiveSessionsChangedListener(mSessionListener, mComponent);
mSessionListener.setMediaController(this);
mSessionListening = true;
} catch (SecurityException exception) {
Log.w(TAG, "Failed to start Lollipop media controller: " + exception.getMessage());
// Try to unregister it, just it case.
try {
mMediaSessionManager.removeOnActiveSessionsChangedListener(mSessionListener);
} catch (Exception e) { /* unused */ } finally {
mMediaSessionManager = null;
mSessionListening = false;
}
// Media controller needs notification listener service
// permissions to be granted.
return;
}
List<MediaController> controllers = mMediaSessionManager.getActiveSessions(mComponent);
mSessionListener.onActiveSessionsChanged(controllers);
}
示例10: registerFallbackControllerCallback
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void registerFallbackControllerCallback(Context context, MediaControllerCallback controllerCallback) {
MediaSessionManager mediaSessionManager = ((MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE));
ComponentName className = new ComponentName(context.getApplicationContext(), NotificationListenerService.class);
if (sessionListener != null)
mediaSessionManager.removeOnActiveSessionsChangedListener(sessionListener);
sessionListener = list -> controllerCallback.registerActiveSessionCallback(context, list);
mediaSessionManager.addOnActiveSessionsChangedListener(sessionListener, className);
controllerCallback.registerActiveSessionCallback(context, mediaSessionManager.getActiveSessions(className));
}
示例11: onCreate
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
sRunning = true;
try {
mediaControllerCallback = new MediaControllerCallback(this);
MediaSessionManager.OnActiveSessionsChangedListener sessionsChangedListener =
list -> mediaControllerCallback.registerActiveSessionCallback(ScrobblerService.this, list);
listener = new WeakReference<>(sessionsChangedListener);
MediaSessionManager manager = ((MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE));
ComponentName className = new ComponentName(getApplicationContext(), NotificationListenerService.class);
manager.addOnActiveSessionsChangedListener(sessionsChangedListener, className);
List<MediaController> controllers = manager.getActiveSessions(className);
mediaControllerCallback.registerActiveSessionCallback(ScrobblerService.this, controllers);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SharedPreferences current = getSharedPreferences("current_music", Context.MODE_PRIVATE);
String artist = current.getString("artist", "");
String track = current.getString("track", "");
startForeground(NOTIFICATION_ID, NotificationUtil.makeNotification(this, artist, track, 0L, false, false));
}
if (!controllers.isEmpty())
mediaControllerCallback.broadcastControllerState(this, controllers.get(0), null);
} catch (Exception e) {
e.printStackTrace();
return;
}
Log.d("geecko", "mediaControllerCallback registered");
}
示例12: onDestroy
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@Override
public void onDestroy() {
super.onDestroy();
sRunning = false;
this.mBinder = null;
if (listener != null && listener.get() != null)
((MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE)).removeOnActiveSessionsChangedListener(listener.get());
if (mediaControllerCallback != null) {
mediaControllerCallback.removeControllerCallback();
mediaControllerCallback = null;
}
}
示例13: onCreate
import android.media.session.MediaSessionManager; //导入依赖的package包/类
void onCreate(MediaAppListAdapter mediaAppListAdapter) {
mMediaSessionApps = mediaAppListAdapter.addSection(R.string.media_app_header_session);
mMediaSessionManager = (MediaSessionManager)
getSystemService(Context.MEDIA_SESSION_SERVICE);
}
示例14: getMediaSessionManager
import android.media.session.MediaSessionManager; //导入依赖的package包/类
/**
* 返回 {@link MediaSessionManager}
*/
public static MediaSessionManager getMediaSessionManager()
{
return (MediaSessionManager) get(MEDIA_SESSION_SERVICE);
}
示例15: getMediaSessionManager
import android.media.session.MediaSessionManager; //导入依赖的package包/类
@TargetApi(21)
public static MediaSessionManager getMediaSessionManager() {
return (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
}