Example usage for android.media RemoteControlClient PLAYSTATE_STOPPED

List of usage examples for android.media RemoteControlClient PLAYSTATE_STOPPED

Introduction

In this page you can find the example usage for android.media RemoteControlClient PLAYSTATE_STOPPED.

Prototype

int PLAYSTATE_STOPPED

To view the source code for android.media RemoteControlClient PLAYSTATE_STOPPED.

Click Source Link

Document

Playback state of a RemoteControlClient which is stopped.

Usage

From source file:github.popeen.dsub.util.compat.RemoteControlClientLP.java

@Override
public void setPlaybackState(int state, int index, int queueSize) {
    PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();

    int newState = PlaybackStateCompat.STATE_NONE;
    switch (state) {
    case RemoteControlClient.PLAYSTATE_PLAYING:
        newState = PlaybackStateCompat.STATE_PLAYING;
        break;/*from   ww w  . j a  v  a 2s  . co  m*/
    case RemoteControlClient.PLAYSTATE_STOPPED:
        newState = PlaybackStateCompat.STATE_STOPPED;
        break;
    case RemoteControlClient.PLAYSTATE_PAUSED:
        newState = PlaybackStateCompat.STATE_PAUSED;
        break;
    case RemoteControlClient.PLAYSTATE_BUFFERING:
        newState = PlaybackStateCompat.STATE_BUFFERING;
        break;
    }

    long position = -1;
    if (state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) {
        position = downloadService.getPlayerPosition();
    }
    builder.setState(newState, position, 1.0f);
    DownloadFile downloadFile = downloadService.getCurrentPlaying();
    Entry entry = null;
    boolean isSong = true;
    if (downloadFile != null) {
        entry = downloadFile.getSong();
        isSong = entry.isSong();
    }

    builder.setActions(getPlaybackActions(isSong, index, queueSize));

    if (entry != null) {
        addCustomActions(entry, builder);
        builder.setActiveQueueItemId(entry.getId().hashCode());
    }

    PlaybackStateCompat playbackState = builder.build();
    mediaSession.setPlaybackState(playbackState);
    previousState = state;
}

From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java

void processStopRequest(boolean force) {
    if (mState == State.Playing || mState == State.Paused || force) {
        mState = State.Stopped;/*from   ww w  .jav  a 2s  .c om*/

        // let go of all resources...
        relaxResources(true);
        giveUpAudioFocus();

        // Tell any remote controls that our playback state is 'paused'.
        if (mRemoteControlClientCompat != null) {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        }

        // service is no longer necessary. Will be started again if needed.
        stopSelf();
    }
}

From source file:com.yamin.kk.service.AudioService.java

/**
 * A function to control the Remote Control Client. It is needed for
 * compatibility with devices below Ice Cream Sandwich (4.0).
 *
 * @param p Playback state// w  w  w  .  j  a  v a2  s . c o  m
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteControlClientPlaybackState(int state) {
    if (!Util.isICSOrLater() || mRemoteControlClient == null)
        return;

    switch (state) {
    case EventHandler.MediaPlayerPlaying:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
        break;
    case EventHandler.MediaPlayerPaused:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
        break;
    case EventHandler.MediaPlayerStopped:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        break;
    }
}

From source file:io.radio.streamer.MainActivity.java

@TargetApi(14)
private void initializeRemoteControls() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ComponentName eventReceiver = new ComponentName(getPackageName(),
                RemoteControlReceiver.class.getName());

        audioManager.registerMediaButtonEventReceiver(eventReceiver);
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setComponent(eventReceiver);
        PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
                mediaButtonIntent, 0);/*from  w w w . ja va 2 s  . c o m*/
        remoteControlClient = new RemoteControlClient(mediaPendingIntent);
        remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);
        audioManager.registerRemoteControlClient(remoteControlClient);
    }
}

From source file:com.dzt.musicplay.player.AudioService.java

/**
 * A function to control the Remote Control Client. It is needed for
 * compatibility with devices below Ice Cream Sandwich (4.0).
 * /*from ww  w.  j  a va2 s. c om*/
 * @param p
 *            Playback state
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteControlClientPlaybackState(int state) {
    if (!LibVlcUtil.isICSOrLater() || mRemoteControlClient == null)
        return;

    switch (state) {
    case EventHandler.MediaPlayerPlaying:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
        break;
    case EventHandler.MediaPlayerPaused:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
        break;
    case EventHandler.MediaPlayerStopped:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        break;
    }
}

From source file:org.videolan.vlc.PlaybackService.java

/**
 * A function to control the Remote Control Client. It is needed for
 * compatibility with devices below Ice Cream Sandwich (4.0).
 *
 * @param state Playback state//from  w  w  w . ja  v  a  2 s .c  om
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteControlClientPlaybackState(int state) {
    if (!AndroidUtil.isICSOrLater() || mRemoteControlClient == null)
        return;

    switch (state) {
    case EventHandler.MediaPlayerPlaying:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
        break;
    case EventHandler.MediaPlayerPaused:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
        break;
    case EventHandler.MediaPlayerStopped:
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        break;
    }
}

From source file:co.shunya.gita.player.MusicService.java

void processStopRequest(boolean force) {
    if (mState == State.Playing || mState == State.Paused || force) {
        setState(State.Stopped);/*w  w w  .j  a  v  a 2s. c o m*/

        // let go of all resources...
        relaxResources(true);
        giveUpAudioFocus();

        // Tell any remote controls that our playback state is 'paused'.
        if (mRemoteControlClientCompat != null) {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        }

        // service is no longer necessary. Will be started again if needed.
        BusProvider.getMediaEventBus().unregister(this);
        stopSelf();

    }
}

From source file:com.nd.android.u.square.service.MusicPlaybackService.java

void processStopRequest(boolean force) {
    if (mState == State.Playing || mState == State.Paused || force) {
        mState = State.Stopped;/*from w w  w. j  a v a  2s . com*/

        // let go of all resources...
        relaxResources(true);
        giveUpAudioFocus();

        if (null != sOnStateChangedListener)
            sOnStateChangedListener.onPlayerStopped(this);

        // Tell any remote controls that our playback state is 'paused'.
        if (mRemoteControlClientCompat != null) {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        }

        // MusicPlaybackService?SquareActivity??????
        // stopSelf();
    }
}

From source file:com.iamplus.musicplayer.MusicService.java

void processStopRequest(boolean force) {
    if (mState == State.Playing || mState == State.Paused || force) {
        mState = State.Stopped;//from  ww w  .  java 2s  .c o  m

        // let go of all resources...
        relaxResources(true);
        giveUpAudioFocus();

        // Tell any remote controls that our playback state is 'paused'.
        if (mRemoteControlClientCompat != null) {
            mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        }

        // service is no longer necessary. Will be started again if needed.
        stopSelf();

        if (mWakeLock.isHeld())
            mWakeLock.release();

        if (mPlayerEventListener != null) {
            mPlayerEventListener.onPlaybackCompleted();
        }
    }
}

From source file:com.namelessdev.mpdroid.NotificationService.java

/**
 * Get the RemoteControlClient status for the corresponding MPDStatus
 *
 * @param mpdStatus MPDStatus to parse/*from w  ww  . jav  a  2  s  .co  m*/
 * @return state to give to RemoteControlClient
 */
private int getRemoteState(final MPDStatus mpdStatus) {
    final int state;

    if (mpdStatus == null) {
        state = RemoteControlClient.PLAYSTATE_ERROR;
    } else if (mediaPlayerServiceIsBuffering) {
        state = RemoteControlClient.PLAYSTATE_BUFFERING;
    } else {
        switch (mpdStatus.getState()) {
        case MPDStatus.MPD_STATE_PLAYING:
            state = RemoteControlClient.PLAYSTATE_PLAYING;
            break;
        case MPDStatus.MPD_STATE_STOPPED:
            state = RemoteControlClient.PLAYSTATE_STOPPED;
            break;
        default:
            state = RemoteControlClient.PLAYSTATE_PAUSED;
            break;
        }
    }
    return state;
}