Search in sources :

Example 1 with MediaController

use of android.media.session.MediaController in project platform_frameworks_base by android.

the class PhoneStatusBar method findAndUpdateMediaNotifications.

public void findAndUpdateMediaNotifications() {
    boolean metaDataChanged = false;
    synchronized (mNotificationData) {
        ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
        final int N = activeNotifications.size();
        // Promote the media notification with a controller in 'playing' state, if any.
        Entry mediaNotification = null;
        MediaController controller = null;
        for (int i = 0; i < N; i++) {
            final Entry entry = activeNotifications.get(i);
            if (isMediaNotification(entry)) {
                final MediaSession.Token token = entry.notification.getNotification().extras.getParcelable(Notification.EXTRA_MEDIA_SESSION);
                if (token != null) {
                    MediaController aController = new MediaController(mContext, token);
                    if (PlaybackState.STATE_PLAYING == getMediaControllerPlaybackState(aController)) {
                        if (DEBUG_MEDIA) {
                            Log.v(TAG, "DEBUG_MEDIA: found mediastyle controller matching " + entry.notification.getKey());
                        }
                        mediaNotification = entry;
                        controller = aController;
                        break;
                    }
                }
            }
        }
        if (mediaNotification == null) {
            if (mMediaSessionManager != null) {
                final List<MediaController> sessions = mMediaSessionManager.getActiveSessionsForUser(null, UserHandle.USER_ALL);
                for (MediaController aController : sessions) {
                    if (PlaybackState.STATE_PLAYING == getMediaControllerPlaybackState(aController)) {
                        // now to see if we have one like this
                        final String pkg = aController.getPackageName();
                        for (int i = 0; i < N; i++) {
                            final Entry entry = activeNotifications.get(i);
                            if (entry.notification.getPackageName().equals(pkg)) {
                                if (DEBUG_MEDIA) {
                                    Log.v(TAG, "DEBUG_MEDIA: found controller matching " + entry.notification.getKey());
                                }
                                controller = aController;
                                mediaNotification = entry;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (controller != null && !sameSessions(mMediaController, controller)) {
            // We have a new media session
            clearCurrentMediaNotification();
            mMediaController = controller;
            mMediaController.registerCallback(mMediaListener);
            mMediaMetadata = mMediaController.getMetadata();
            if (DEBUG_MEDIA) {
                Log.v(TAG, "DEBUG_MEDIA: insert listener, receive metadata: " + mMediaMetadata);
            }
            if (mediaNotification != null) {
                mMediaNotificationKey = mediaNotification.notification.getKey();
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Found new media notification: key=" + mMediaNotificationKey + " controller=" + mMediaController);
                }
            }
            metaDataChanged = true;
        }
    }
    if (metaDataChanged) {
        updateNotifications();
    }
    updateMediaMetaData(metaDataChanged, true);
}
Also used : Entry(com.android.systemui.statusbar.NotificationData.Entry) MediaController(android.media.session.MediaController) MediaSession(android.media.session.MediaSession) StatusBarManager.windowStateToString(android.app.StatusBarManager.windowStateToString) Point(android.graphics.Point)

Example 2 with MediaController

use of android.media.session.MediaController in project platform_frameworks_base by android.

the class MediaSessions method onActiveSessionsUpdatedH.

protected void onActiveSessionsUpdatedH(List<MediaController> controllers) {
    if (D.BUG)
        Log.d(TAG, "onActiveSessionsUpdatedH n=" + controllers.size());
    final Set<Token> toRemove = new HashSet<Token>(mRecords.keySet());
    for (MediaController controller : controllers) {
        final Token token = controller.getSessionToken();
        final PlaybackInfo pi = controller.getPlaybackInfo();
        toRemove.remove(token);
        if (!mRecords.containsKey(token)) {
            final MediaControllerRecord r = new MediaControllerRecord(controller);
            r.name = getControllerName(controller);
            mRecords.put(token, r);
            controller.registerCallback(r, mHandler);
        }
        final MediaControllerRecord r = mRecords.get(token);
        final boolean remote = isRemote(pi);
        if (remote) {
            updateRemoteH(token, r.name, pi);
            r.sentRemote = true;
        }
    }
    for (Token t : toRemove) {
        final MediaControllerRecord r = mRecords.get(t);
        r.controller.unregisterCallback(r);
        mRecords.remove(t);
        if (D.BUG)
            Log.d(TAG, "Removing " + r.name + " sentRemote=" + r.sentRemote);
        if (r.sentRemote) {
            mCallbacks.onRemoteRemoved(t);
            r.sentRemote = false;
        }
    }
}
Also used : MediaController(android.media.session.MediaController) PlaybackInfo(android.media.session.MediaController.PlaybackInfo) Token(android.media.session.MediaSession.Token) HashSet(java.util.HashSet)

Example 3 with MediaController

use of android.media.session.MediaController in project platform_frameworks_base by android.

the class PipControlsView method updateMediaController.

private void updateMediaController() {
    MediaController newController = mPipManager.getMediaController();
    if (mMediaController == newController) {
        return;
    }
    if (mMediaController != null) {
        mMediaController.unregisterCallback(mMediaControllerCallback);
    }
    mMediaController = newController;
    if (mMediaController != null) {
        mMediaController.registerCallback(mMediaControllerCallback);
    }
    updatePlayPauseView();
}
Also used : MediaController(android.media.session.MediaController)

Example 4 with MediaController

use of android.media.session.MediaController in project android_frameworks_base by DirtyUnicorns.

the class PhoneStatusBar method findAndUpdateMediaNotifications.

public void findAndUpdateMediaNotifications() {
    boolean metaDataChanged = false;
    synchronized (mNotificationData) {
        ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
        final int N = activeNotifications.size();
        // Promote the media notification with a controller in 'playing' state, if any.
        Entry mediaNotification = null;
        MediaController controller = null;
        for (int i = 0; i < N; i++) {
            final Entry entry = activeNotifications.get(i);
            if (isMediaNotification(entry)) {
                final MediaSession.Token token = entry.notification.getNotification().extras.getParcelable(Notification.EXTRA_MEDIA_SESSION);
                if (token != null) {
                    MediaController aController = new MediaController(mContext, token);
                    if (PlaybackState.STATE_PLAYING == getMediaControllerPlaybackState(aController)) {
                        if (DEBUG_MEDIA) {
                            Log.v(TAG, "DEBUG_MEDIA: found mediastyle controller matching " + entry.notification.getKey());
                        }
                        mediaNotification = entry;
                        controller = aController;
                        break;
                    }
                }
            }
        }
        if (mediaNotification == null) {
            if (mMediaSessionManager != null) {
                final List<MediaController> sessions = mMediaSessionManager.getActiveSessionsForUser(null, UserHandle.USER_ALL);
                for (MediaController aController : sessions) {
                    if (PlaybackState.STATE_PLAYING == getMediaControllerPlaybackState(aController)) {
                        // now to see if we have one like this
                        final String pkg = aController.getPackageName();
                        for (int i = 0; i < N; i++) {
                            final Entry entry = activeNotifications.get(i);
                            if (entry.notification.getPackageName().equals(pkg)) {
                                if (DEBUG_MEDIA) {
                                    Log.v(TAG, "DEBUG_MEDIA: found controller matching " + entry.notification.getKey());
                                }
                                controller = aController;
                                mediaNotification = entry;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (controller != null && !sameSessions(mMediaController, controller)) {
            // We have a new media session
            clearCurrentMediaNotification();
            mMediaController = controller;
            mMediaController.registerCallback(mMediaListener);
            mMediaMetadata = mMediaController.getMetadata();
            if (DEBUG_MEDIA) {
                Log.v(TAG, "DEBUG_MEDIA: insert listener, receive metadata: " + mMediaMetadata);
            }
            if (mediaNotification != null) {
                mMediaNotificationKey = mediaNotification.notification.getKey();
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Found new media notification: key=" + mMediaNotificationKey + " controller=" + mMediaController);
                }
            }
            metaDataChanged = true;
        }
    }
    if (metaDataChanged) {
        updateNotifications();
    }
    updateMediaMetaData(metaDataChanged, true);
}
Also used : Entry(com.android.systemui.statusbar.NotificationData.Entry) MediaController(android.media.session.MediaController) MediaSession(android.media.session.MediaSession) StatusBarManager.windowStateToString(android.app.StatusBarManager.windowStateToString) Point(android.graphics.Point)

Example 5 with MediaController

use of android.media.session.MediaController in project android_frameworks_base by DirtyUnicorns.

the class MediaSessions method onActiveSessionsUpdatedH.

protected void onActiveSessionsUpdatedH(List<MediaController> controllers) {
    if (D.BUG)
        Log.d(TAG, "onActiveSessionsUpdatedH n=" + controllers.size());
    final Set<Token> toRemove = new HashSet<Token>(mRecords.keySet());
    for (MediaController controller : controllers) {
        final Token token = controller.getSessionToken();
        final PlaybackInfo pi = controller.getPlaybackInfo();
        toRemove.remove(token);
        if (!mRecords.containsKey(token)) {
            final MediaControllerRecord r = new MediaControllerRecord(controller);
            r.name = getControllerName(controller);
            mRecords.put(token, r);
            controller.registerCallback(r, mHandler);
        }
        final MediaControllerRecord r = mRecords.get(token);
        final boolean remote = isRemote(pi);
        if (remote) {
            updateRemoteH(token, r.name, pi);
            r.sentRemote = true;
        }
    }
    for (Token t : toRemove) {
        final MediaControllerRecord r = mRecords.get(t);
        r.controller.unregisterCallback(r);
        mRecords.remove(t);
        if (D.BUG)
            Log.d(TAG, "Removing " + r.name + " sentRemote=" + r.sentRemote);
        if (r.sentRemote) {
            mCallbacks.onRemoteRemoved(t);
            r.sentRemote = false;
        }
    }
}
Also used : MediaController(android.media.session.MediaController) PlaybackInfo(android.media.session.MediaController.PlaybackInfo) Token(android.media.session.MediaSession.Token) HashSet(java.util.HashSet)

Aggregations

MediaController (android.media.session.MediaController)31 Token (android.media.session.MediaSession.Token)10 StatusBarManager.windowStateToString (android.app.StatusBarManager.windowStateToString)5 Point (android.graphics.Point)5 PlaybackInfo (android.media.session.MediaController.PlaybackInfo)5 MediaSession (android.media.session.MediaSession)5 MediaSessionManager (android.media.session.MediaSessionManager)5 Entry (com.android.systemui.statusbar.NotificationData.Entry)5 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 HashSet (java.util.HashSet)5 MediaExpandableNotificationRow (com.android.systemui.statusbar.MediaExpandableNotificationRow)2 MediaMetadata (android.media.MediaMetadata)1 PlaybackState (android.media.session.PlaybackState)1 Bundle (android.os.Bundle)1 SpannableString (android.text.SpannableString)1 MusicSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicSpec)1 MusicStateSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec)1