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


Java MediaSessionManager.addOnActiveSessionsChangedListener方法代码示例

本文整理汇总了Java中android.media.session.MediaSessionManager.addOnActiveSessionsChangedListener方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionManager.addOnActiveSessionsChangedListener方法的具体用法?Java MediaSessionManager.addOnActiveSessionsChangedListener怎么用?Java MediaSessionManager.addOnActiveSessionsChangedListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.session.MediaSessionManager的用法示例。


在下文中一共展示了MediaSessionManager.addOnActiveSessionsChangedListener方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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) {

    }
}
 
开发者ID:jathak,项目名称:sflauncher,代码行数:19,代码来源:MediaListener.java

示例2: 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));
}
 
开发者ID:jathak,项目名称:musicwidget,代码行数:16,代码来源:NotificationListener.java

示例3: 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");
    }
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:12,代码来源:MediaService.java

示例4: 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);
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:40,代码来源:ListenerService.java

示例5: 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;
}
 
开发者ID:Tombarr,项目名称:Noyze,代码行数:9,代码来源:RemoteControlLollipop.java

示例6: 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);
}
 
开发者ID:AChep,项目名称:AcDisplay,代码行数:40,代码来源:MediaController2Lollipop.java

示例7: 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));
}
 
开发者ID:QuickLyric,项目名称:QuickLyric,代码行数:11,代码来源:MediaControllerCallback.java

示例8: 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");
}
 
开发者ID:QuickLyric,项目名称:QuickLyric,代码行数:30,代码来源:ScrobblerService.java


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