Example usage for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED

List of usage examples for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED

Introduction

In this page you can find the example usage for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED.

Prototype

int STATE_PAUSED

To view the source code for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED.

Click Source Link

Document

State indicating this item is currently paused.

Usage

From source file:com.rks.musicx.services.MediaSession.java

public static void lockscreenMedia(MediaSessionCompat mediaSessionCompat, MusicXService musicXService,
        String what) {//ww w.ja  v  a 2  s. c  o m
    if (musicXService == null) {
        return;
    }
    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    if (what.equals(PLAYSTATE_CHANGED) || what.equals(META_CHANGED)) {
        int state = MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying()
                ? PlaybackStateCompat.STATE_PAUSED
                : PlaybackStateCompat.STATE_PLAYING;
        mediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder()
                .setState(state, musicXService.getPlayerPos(), 1.0f)
                .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE
                        | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT
                        | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
                .build());

        builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, musicXService.getsongTitle());
        builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, musicXService.getDuration());
        builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, musicXService.getsongArtistName());
        builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, musicXService.getsongAlbumName());
        handler.post(new Runnable() {
            @Override
            public void run() {
                ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(),
                        musicXService.getsongAlbumID(), new palette() {
                            @Override
                            public void palettework(Palette palette) {

                            }
                        }, new bitmap() {
                            @Override
                            public void bitmapwork(Bitmap bitmap) {
                                builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap);
                                mediaSessionCompat.setMetadata(builder.build());
                            }

                            @Override
                            public void bitmapfailed(Bitmap bitmap) {
                                builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap);
                                mediaSessionCompat.setMetadata(builder.build());
                            }
                        });
            }
        });
    }
}

From source file:com.thelotradio.android.PlayerActivity.java

@Override
public void onClick(View view) {
    MediaControllerCompat controller = getSupportMediaController();
    if (controller != null) {
        int state = controller.getPlaybackState().getState();
        if (state == PlaybackStateCompat.STATE_PAUSED) {
            controller.getTransportControls().play();
        } else if (state == PlaybackStateCompat.STATE_PLAYING) {
            controller.getTransportControls().pause();
        }/*from   w  w  w  . ja  v  a  2s. c  om*/
    }
}

From source file:org.runbuddy.tomahawk.mediaplayers.AndroidMediaPlayer.java

@Override
public void pause() {
    mPlayState = PlaybackStateCompat.STATE_PAUSED;
    handlePlayState();
}

From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java

@NonNull
static SparseIntArray generatePlaybackCompatSparse() {
    SparseIntArray sia = new SparseIntArray();
    sia.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
    sia.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
    sia.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
    sia.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
    sia.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
    sia.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING, PlaybackStateCompat.STATE_FAST_FORWARDING);
    sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
    sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);
    return sia;//from   w w w . jav a 2 s.  c  o  m
}

From source file:net.simno.klingar.playback.PlaybackManager.java

void updatePlaybackState() {
    long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    if (playback != null && playback.isConnected()) {
        position = playback.getCurrentStreamPosition();
    }/*from  w  w  w. j  a  va 2  s. c o m*/

    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions());

    addCustomActions(stateBuilder);

    @State
    int state = playback.getState();
    stateBuilder.setState(state, position, 1.0f, androidClock.elapsedRealTime());

    serviceCallback.onPlaybackStateUpdated(stateBuilder.build());

    if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) {
        serviceCallback.onNotificationRequired();
    }
}

From source file:org.runbuddy.tomahawk.ui.fragments.AlbumsFragment.java

/**
 * Called every time an item inside a ListView or GridView is clicked
 *
 * @param view the clicked view// w  ww . j a  v a2s. c  o m
 * @param item the Object which corresponds to the click
 */
@Override
public void onItemClick(View view, final Object item, Segment segment) {
    if (getMediaController() == null) {
        Log.e(TAG, "onItemClick failed because getMediaController() is null");
        return;
    }
    if (item instanceof PlaylistEntry) {
        final PlaylistEntry entry = (PlaylistEntry) item;
        if (entry.getQuery().isPlayable()) {
            if (getPlaybackManager().getCurrentEntry() == entry) {
                // if the user clicked on an already playing track
                int playState = getMediaController().getPlaybackState().getState();
                if (playState == PlaybackStateCompat.STATE_PLAYING) {
                    getMediaController().getTransportControls().pause();
                } else if (playState == PlaybackStateCompat.STATE_PAUSED) {
                    getMediaController().getTransportControls().play();
                }
            } else {
                if (!TomahawkApp.PLUGINNAME_HATCHET.equals(mCollection.getId())) {
                    mCollection.getArtistTracks(mArtist).done(new DoneCallback<Playlist>() {
                        @Override
                        public void onDone(Playlist topHits) {
                            getPlaybackManager().setPlaylist(topHits, entry);
                            getMediaController().getTransportControls().play();
                        }
                    });
                } else {
                    HatchetCollection collection = (HatchetCollection) mCollection;
                    collection.getArtistTopHits(mArtist).done(new DoneCallback<Playlist>() {
                        @Override
                        public void onDone(Playlist topHits) {
                            getPlaybackManager().setPlaylist(topHits, entry);
                            getMediaController().getTransportControls().play();
                        }
                    });
                }
            }
        }
    } else if (item instanceof Album) {
        Album album = (Album) item;
        mCollection.getAlbumTracks(album).done(new DoneCallback<Playlist>() {
            @Override
            public void onDone(Playlist playlist) {
                Bundle bundle = new Bundle();
                bundle.putString(TomahawkFragment.ALBUM, ((Album) item).getCacheKey());
                if (playlist != null) {
                    bundle.putString(TomahawkFragment.COLLECTION_ID, mCollection.getId());
                } else {
                    bundle.putString(TomahawkFragment.COLLECTION_ID, TomahawkApp.PLUGINNAME_HATCHET);
                }
                bundle.putInt(CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_DYNAMIC);
                FragmentUtils.replace((TomahawkMainActivity) getActivity(), PlaylistEntriesFragment.class,
                        bundle);
            }
        });
    }
}

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*from  w w w  . j  ava  2 s .c o  m*/
 */
protected MediaController2KitKat(@NonNull Activity activity) {
    super(activity);

    SparseIntArray cachedStateSparse = sStateSparse.get();
    if (cachedStateSparse == null) {
        mStateSparse = new SparseIntArray();
        mStateSparse.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING,
                PlaybackStateCompat.STATE_FAST_FORWARDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);

        // Cache sparse array
        sStateSparse = new WeakReference<>(mStateSparse);
    } else {
        mStateSparse = cachedStateSparse;
    }
}

From source file:com.classiqo.nativeandroid_32bitz.playback.PlaybackManager.java

public void updatePlaybackState(String error) {
    LogHelper.d(TAG, "updatePlaybackState, playback state = " + mPlayback.getState());

    long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    if (mPlayback != null && mPlayback.isConnected()) {
        position = mPlayback.getCurrentStreamPosition();
    }/* w w  w  . j  a  va 2s.com*/

    //noinspection ResourceType
    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions());

    setCustomAction(stateBuilder);
    int state = mPlayback.getState();

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackStateCompat.STATE_ERROR;
    }
    //noinspection ResourceType
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());

    MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic();

    if (currentMusic != null) {
        stateBuilder.setActiveQueueItemId(currentMusic.getQueueId());
    }

    mServiceCallback.onPlaybackStateUpdated(stateBuilder.build());

    if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) {
        mServiceCallback.onNotificationRequired();
    }
}

From source file:nuclei.media.MediaPlayerController.java

@Override
public void start() {
    if (mMediaId == null)
        return;/*from  w w  w. j  a  v a  2  s.  co  m*/
    if (mMediaControls != null) {
        if (mCallbacks != null) {
            mCallbacks.onLoading(this);
        }
        String currentMediaId = null;
        MediaMetadataCompat metadataCompat = mMediaControls.getMetadata();
        if (metadataCompat != null) {
            MediaDescriptionCompat descriptionCompat = metadataCompat.getDescription();
            if (descriptionCompat != null) {
                currentMediaId = descriptionCompat.getMediaId();
            }
        }
        final String id = mMediaId.toString();
        if (mCallbacks != null
                && mCallbacks.onPlay(currentMediaId, id, this, mMediaControls.getTransportControls()))
            return;
        if (mCallbacks != null)
            mCallbacks.onPlaying(this);
        if (currentMediaId != null && currentMediaId.equals(id)
                && mMediaControls.getPlaybackState().getState() == PlaybackStateCompat.STATE_PAUSED) {
            mMediaControls.getTransportControls().play();
        } else {
            mMediaControls.getTransportControls().playFromMediaId(id, null);
        }
    } else {
        mStartWhenReady = true;
    }
}

From source file:org.runbuddy.tomahawk.mediaplayers.VLCMediaPlayer.java

/**
 * Pause playing the current {@link org.runbuddy.libtomahawk.collection.Track}
 *//* w ww.j  ava  2 s.  c o  m*/
@Override
public void pause() throws IllegalStateException {
    Log.d(TAG, "pause()");
    mPlayState = PlaybackStateCompat.STATE_PAUSED;
    handlePlayState();
}