Search in sources :

Example 11 with PlaybackState

use of android.media.session.PlaybackState in project android_frameworks_base by ResurrectionRemix.

the class QueueView method updateQueue.

/**
     * @param queue
     * @return whether the queue size has changed
     */
public boolean updateQueue(List<MediaSession.QueueItem> queue) {
    int queueSizeBefore = mAdapter.getCount();
    mQueue.clear();
    if (queue != null) {
        // add everything *after* the currently playing item
        boolean foundNowPlaying = false;
        final PlaybackState playbackState = mController.getPlaybackState();
        long activeQueueId = -1;
        if (playbackState != null) {
            activeQueueId = playbackState.getActiveQueueItemId();
        }
        for (int i = 0; i < queue.size() && mQueue.size() < getMaxQueueRowCount(); i++) {
            final MediaSession.QueueItem item = queue.get(i);
            if (!foundNowPlaying && activeQueueId != -1 && activeQueueId == item.getQueueId()) {
                foundNowPlaying = true;
                continue;
            }
            if (foundNowPlaying) {
                mQueue.add(item);
            }
        }
        // add everything
        if (!foundNowPlaying) {
            for (int i = 0; i < getMaxQueueRowCount() && i < queue.size(); i++) {
                mQueue.add(queue.get(i));
            }
        }
    }
    mAdapter.notifyDataSetChanged();
    return mAdapter.getCount() != queueSizeBefore;
}
Also used : MediaSession(android.media.session.MediaSession) PlaybackState(android.media.session.PlaybackState)

Example 12 with PlaybackState

use of android.media.session.PlaybackState in project android_frameworks_base by ResurrectionRemix.

the class MediaSessions method dump.

private static void dump(int n, PrintWriter writer, MediaController c) {
    writer.println("  Controller " + n + ": " + c.getPackageName());
    final Bundle extras = c.getExtras();
    final long flags = c.getFlags();
    final MediaMetadata mm = c.getMetadata();
    final PlaybackInfo pi = c.getPlaybackInfo();
    final PlaybackState playbackState = c.getPlaybackState();
    final List<QueueItem> queue = c.getQueue();
    final CharSequence queueTitle = c.getQueueTitle();
    final int ratingType = c.getRatingType();
    final PendingIntent sessionActivity = c.getSessionActivity();
    writer.println("    PlaybackState: " + Util.playbackStateToString(playbackState));
    writer.println("    PlaybackInfo: " + Util.playbackInfoToString(pi));
    if (mm != null) {
        writer.println("  MediaMetadata.desc=" + mm.getDescription());
    }
    writer.println("    RatingType: " + ratingType);
    writer.println("    Flags: " + flags);
    if (extras != null) {
        writer.println("    Extras:");
        for (String key : extras.keySet()) {
            writer.println("      " + key + "=" + extras.get(key));
        }
    }
    if (queueTitle != null) {
        writer.println("    QueueTitle: " + queueTitle);
    }
    if (queue != null && !queue.isEmpty()) {
        writer.println("    Queue:");
        for (QueueItem qi : queue) {
            writer.println("      " + qi);
        }
    }
    if (pi != null) {
        writer.println("    sessionActivity: " + sessionActivity);
    }
}
Also used : Bundle(android.os.Bundle) PlaybackInfo(android.media.session.MediaController.PlaybackInfo) MediaMetadata(android.media.MediaMetadata) PlaybackState(android.media.session.PlaybackState) QueueItem(android.media.session.MediaSession.QueueItem) PendingIntent(android.app.PendingIntent)

Example 13 with PlaybackState

use of android.media.session.PlaybackState in project android_frameworks_base by crdroidandroid.

the class MediaSessionRecord method getStateWithUpdatedPosition.

private PlaybackState getStateWithUpdatedPosition() {
    PlaybackState state;
    long duration = -1;
    synchronized (mLock) {
        state = mPlaybackState;
        if (mMetadata != null && mMetadata.containsKey(MediaMetadata.METADATA_KEY_DURATION)) {
            duration = mMetadata.getLong(MediaMetadata.METADATA_KEY_DURATION);
        }
    }
    PlaybackState result = null;
    if (state != null) {
        if (state.getState() == PlaybackState.STATE_PLAYING || state.getState() == PlaybackState.STATE_FAST_FORWARDING || state.getState() == PlaybackState.STATE_REWINDING) {
            long updateTime = state.getLastPositionUpdateTime();
            long currentTime = SystemClock.elapsedRealtime();
            if (updateTime > 0) {
                long position = (long) (state.getPlaybackSpeed() * (currentTime - updateTime)) + state.getPosition();
                if (duration >= 0 && position > duration) {
                    position = duration;
                } else if (position < 0) {
                    position = 0;
                }
                PlaybackState.Builder builder = new PlaybackState.Builder(state);
                builder.setState(state.getState(), position, state.getPlaybackSpeed(), currentTime);
                result = builder.build();
            }
        }
    }
    return result == null ? state : result;
}
Also used : PlaybackState(android.media.session.PlaybackState)

Aggregations

PlaybackState (android.media.session.PlaybackState)13 MediaMetadata (android.media.MediaMetadata)6 Bundle (android.os.Bundle)6 PendingIntent (android.app.PendingIntent)5 PlaybackInfo (android.media.session.MediaController.PlaybackInfo)5 QueueItem (android.media.session.MediaSession.QueueItem)5 MediaSession (android.media.session.MediaSession)2 MediaController (android.media.session.MediaController)1 MusicSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicSpec)1 MusicStateSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec)1