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


Java MediaSessionManager类代码示例

本文整理汇总了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) {

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

示例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;
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:10,代码来源:LaunchActivity.java

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

示例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!");
    }
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:23,代码来源:AnswerCallAction.java

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

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

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

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

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

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

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

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

示例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);
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:6,代码来源:LaunchActivity.java

示例14: getMediaSessionManager

import android.media.session.MediaSessionManager; //导入依赖的package包/类
/**
 * 返回 {@link MediaSessionManager}
 */
public static MediaSessionManager getMediaSessionManager()
{
    return (MediaSessionManager) get(MEDIA_SESSION_SERVICE);
}
 
开发者ID:Ayvytr,项目名称:EasyAndroid,代码行数:8,代码来源:Managers.java

示例15: getMediaSessionManager

import android.media.session.MediaSessionManager; //导入依赖的package包/类
@TargetApi(21)
public static MediaSessionManager getMediaSessionManager() {
    return (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
}
 
开发者ID:simplesoft-duongdt3,项目名称:Android-App-Template,代码行数:5,代码来源:ServiceUtil.java


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