當前位置: 首頁>>代碼示例>>Java>>正文


Java PlaybackStateCompat.STATE_PLAYING屬性代碼示例

本文整理匯總了Java中android.support.v4.media.session.PlaybackStateCompat.STATE_PLAYING屬性的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackStateCompat.STATE_PLAYING屬性的具體用法?Java PlaybackStateCompat.STATE_PLAYING怎麽用?Java PlaybackStateCompat.STATE_PLAYING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.support.v4.media.session.PlaybackStateCompat的用法示例。


在下文中一共展示了PlaybackStateCompat.STATE_PLAYING屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateRemoteControlClient

/**
 * Updates the lockscreen controls.
 *
 * @param what The broadcast
 */
private void updateRemoteControlClient(final String what) {
    int playState = isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
    PlaybackStateCompat pmc = new PlaybackStateCompat.Builder()
            .setState(playState, position(), 1.0f)
            .setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
            .build();
    switch (what) {
        case PLAYSTATE_CHANGED:
        case POSITION_CHANGED:
            mMediaSession.setPlaybackState(pmc);
            break;
        case META_CHANGED:
            mMediaSession.setMetadata(new MediaMetadataCompat.Builder()
                    .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName())
                    .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName())
                    .putString(MediaMetadataCompat.METADATA_KEY_TITLE, getTrackName())
                    //.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getAlbumCover())
                    .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration())
                    .build());

            break;
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:28,代碼來源:MusicPlaybackService.java

示例2: run

@Override
public void run() {
    int state = mediaPlayer.getPlaybackState();
    if (state == ExoPlayer.STATE_READY) {
        long pos = mediaPlayer.getCurrentPosition();
        float speed = mediaPlayer.getPlaybackParameters().speed;

        if (!notificationManager.startNotification()) {
            notificationManager.updateNotification();
        }
        stateBuilder.setBufferedPosition(mediaPlayer.getBufferedPercentage());
        int sessionState = mediaPlayer.getPlayWhenReady() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
        mediaSession.setPlaybackState(stateBuilder.setState(sessionState, pos, speed).build());
        if (mediaPlayer.getPlayWhenReady()) {
            progressHandler.postDelayed(progressRunnable, 1000 - (pos % 1000));
        }
    }
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:18,代碼來源:MediaPlayerService.java

示例3: updatePlayer

@Override
public void updatePlayer() {
    if (player != null) {
        switch (focusState) {
            case AUDIO_NO_FOCUS_NO_DUCK:
                if (playerState == PlaybackStateCompat.STATE_PLAYING) {
                    pause();
                }
                return;
            case AUDIO_NO_FOCUS_CAN_DUCK:
                registerNoiseReceiver();
                player.setVolume(VOLUME_DUCK, VOLUME_DUCK);
                break;
            default:
                registerNoiseReceiver();
                player.setVolume(VOLUME_NORMAL,VOLUME_NORMAL);
        }
        player.start();
        playerState=PlaybackStateCompat.STATE_PLAYING;
        if(callback!=null) callback.onPlay();
    }
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:22,代碼來源:MediaPlayback.java

示例4: getPlayPauseAction

private NotificationCompat.Action getPlayPauseAction() {
    int icon;
    String title;
    PendingIntent pi;
    if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) {
        icon = android.R.drawable.ic_media_pause;
        title = "pause";
        pi = mPauseIntent;
    } else {
        icon = android.R.drawable.ic_media_play;
        title = "play";
        pi = mPlayIntent;
    }
    return new NotificationCompat.Action(icon, title, pi);
}
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:15,代碼來源:NovaNotificationManager.java

示例5: onSeekComplete

@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
    Log.i(TAG, "onSeekComplete, current position: " + mCurrentPosition);
    mCurrentPosition = mediaPlayer.getCurrentPosition();
    if (mPlaybackState == PlaybackStateCompat.STATE_BUFFERING) {
        mPlayer.start();
        mPlaybackState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlayStateChanged(mPlaybackState);
    }
}
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:12,代碼來源:LocalPlayback.java

示例6: configMediaPlayerState

/**
 * Reconfigures MediaPlayer according to audio focus settings and
 * starts/restarts it. This method starts/restarts the MediaPlayer
 * respecting the current audio focus state. So if we have focus, it will
 * play normally; if we don't have focus, it will either leave the
 * MediaPlayer paused or set it to a low volume, depending on what is
 * allowed by the current focus settings. This method assumes mPlayer !=
 * null, so if you are calling it, you have to do so from a context where
 * you are sure this is the case.
 */
private void configMediaPlayerState() {
    if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
        // If we don't have audio focus and can't duck, we have to pause,
        if (mState == PlaybackStateCompat.STATE_PLAYING) {
            pause();
        }
    } else {  // we have audio focus:
        registerAudioNoisyReceiver();
        if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
            mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
        } else {
            if (mMediaPlayer != null) {
                mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
            } // else do something for remote client.
        }
        // If we were playing when we lost focus, we need to resume playing.
        if (mPlayOnFocusGain) {
            if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
                if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
                    mMediaPlayer.start();
                    mState = PlaybackStateCompat.STATE_PLAYING;
                } else {
                    mMediaPlayer.seekTo(mCurrentPosition);
                    mState = PlaybackStateCompat.STATE_BUFFERING;
                }
            }
            mPlayOnFocusGain = false;
        }
    }
    if (mCallback != null) {
        mCallback.onPlaybackStateChanged(mState);
    }
}
 
開發者ID:AllThatSeries,項目名稱:react-native-streaming-audio-player,代碼行數:43,代碼來源:Playback.java

示例7: configMediaPlayerState

private void configMediaPlayerState() {
    Logger.d(TAG, "configMediaPlayerState. mAudioFocus=", mAudioFocus);
    if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
        // If we don't have audio focus and can't duck, we have to pause,
        if (mState == PlaybackStateCompat.STATE_PLAYING) {
            mPlayOnFocusGain = false;
            pause();
        }
    } else {  // we have audio focus:
        registerAudioNoisyReceiver();
        if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
            mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
        } else {
            if (mMediaPlayer != null) {
                mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
            } // else do something for remote client.
        }
        // If we were playing when we lost focus, we need to resume playing.
        if (mPlayOnFocusGain) {
            if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
                Logger.d(TAG, "configMediaPlayerState startMediaPlayer. seeking to ",
                        mCurrentPosition);
                if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
                    mMediaPlayer.start();
                    mState = PlaybackStateCompat.STATE_PLAYING;
                } else {
                    mMediaPlayer.seekTo(mCurrentPosition);
                    mState = PlaybackStateCompat.STATE_BUFFERING;
                }
            }
            mPlayOnFocusGain = false;
        }
    }
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:37,代碼來源:AudioPlaybackListener.java

示例8: setNewState

private void setNewState(@PlaybackStateCompat.State int newPlayerState) {
    mState = newPlayerState;

    // Whether playback goes to completion, or whether it is stopped, the
    // mCurrentMediaPlayedToCompletion is set to true.
    if (mState == PlaybackStateCompat.STATE_STOPPED) {
        mCurrentMediaPlayedToCompletion = true;
    }

    // Work around for MediaPlayer.getCurrentPosition() when it changes while not playing.
    final long reportPosition;
    if (mSeekWhileNotPlaying >= 0) {
        reportPosition = mSeekWhileNotPlaying;

        if (mState == PlaybackStateCompat.STATE_PLAYING) {
            mSeekWhileNotPlaying = -1;
        }
    } else {
        reportPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition();
    }

    final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
    stateBuilder.setActions(getAvailableActions());
    stateBuilder.setState(mState,
                          reportPosition,
                          1.0f,
                          SystemClock.elapsedRealtime());
    mPlaybackInfoListener.onPlaybackStateChange(stateBuilder.build());
}
 
開發者ID:nazmulidris,項目名稱:mediasession-mediaplayer,代碼行數:29,代碼來源:MediaPlayerAdapter.java

示例9: onAudioFocusChange

/**
 * Called by AudioManager on audio focus changes.
 * Implementation of {@link AudioManager.OnAudioFocusChangeListener}
 */
@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        // We have gained focus:
        mAudioFocus = AUDIO_FOCUSED;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        boolean canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
        mAudioFocus = canDuck ? AUDIO_NO_FOCUS_CAN_DUCK : AUDIO_NO_FOCUS_NO_DUCK;

        // If we are playing, we need to reset media player by calling configMediaPlayerState
        // with mAudioFocus properly set.
        if (mState == PlaybackStateCompat.STATE_PLAYING && !canDuck) {
            // If we don't have audio focus and can't duck, we save the information that
            // we were playing, so that we can resume playback once we get the focus back.
            mPlayOnFocusGain = true;
        }
    } else {
        Log.e(TAG, "onAudioFocusChange: Ignoring unsupported focusChange: "+ focusChange);
    }
    configMediaPlayerState();
}
 
開發者ID:AllThatSeries,項目名稱:react-native-streaming-audio-player,代碼行數:30,代碼來源:Playback.java

示例10: onAudioFocusChange

/**
 * Called by AudioManager on audio focus changes. Implementation of {@link
 * AudioManager.OnAudioFocusChangeListener}
 */
@Override
public void onAudioFocusChange(int focusChange) {
    boolean gotFullFocus = false;
    boolean canDuck = false;
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        gotFullFocus = true;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
    }

    if (gotFullFocus || canDuck) {
        if (mMediaPlayer != null) {
            if (mPlayOnFocusGain) {
                mPlayOnFocusGain = false;
                mMediaPlayer.start();
                mState = PlaybackStateCompat.STATE_PLAYING;
                updatePlaybackState();
            }
            float volume = canDuck ? 0.2f : 1.0f;
            mMediaPlayer.setVolume(volume, volume);
        }
    } else if (mState == PlaybackStateCompat.STATE_PLAYING) {
        mMediaPlayer.pause();
        mState = PlaybackStateCompat.STATE_PAUSED;
        updatePlaybackState();
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:36,代碼來源:PlaybackManager.java

示例11: onAudioFocusChange

/**
 * Called by AudioManager on audio focus changes. Implementation of {@link
 * AudioManager.OnAudioFocusChangeListener}.
 */
@Override
public void onAudioFocusChange(int focusChange) {
    boolean gotFullFocus = false;
    boolean canDuck = false;
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        gotFullFocus = true;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
    }

    if (gotFullFocus || canDuck) {
        if (mMediaPlayer != null) {
            if (mPlayOnFocusGain) {
                mPlayOnFocusGain = false;
                mMediaPlayer.start();
                mState = PlaybackStateCompat.STATE_PLAYING;
                updatePlaybackState();
            }
            float volume = canDuck ? 0.2f : 1.0f;
            mMediaPlayer.setVolume(volume, volume);
        }
    } else if (mState == PlaybackStateCompat.STATE_PLAYING) {
        mMediaPlayer.pause();
        mState = PlaybackStateCompat.STATE_PAUSED;
        updatePlaybackState();
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:36,代碼來源:PlaybackManager.java

示例12: onSeekComplete

/**
 * Called when MediaPlayer has completed a seek
 *
 * @see OnSeekCompleteListener
 */
@Override
public void onSeekComplete(MediaPlayer mp) {
    mCurrentPosition = mp.getCurrentPosition();
    if (mState == PlaybackStateCompat.STATE_BUFFERING) {
        registerAudioNoisyReceiver();
        mMediaPlayer.start();
        mState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlaybackStateChanged(mState);
    }
}
 
開發者ID:AllThatSeries,項目名稱:react-native-streaming-audio-player,代碼行數:17,代碼來源:Playback.java

示例13: onPlay

@Override
public void onPlay() {
    if (!exoPlayer.getPlayWhenReady()) {
        startService(new Intent(getApplicationContext(), PlayerService.class));

        MusicRepository.Track track = musicRepository.getCurrent();
        updateMetadataFromTrack(track);

        prepareToPlay(track.getUri());

        if (!audioFocusRequested) {
            audioFocusRequested = true;

            int audioFocusResult;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                audioFocusResult = audioManager.requestAudioFocus(audioFocusRequest);
            } else {
                audioFocusResult = audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
            }
            if (audioFocusResult != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
                return;
        }

        mediaSession.setActive(true); // Сразу после получения фокуса

        registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));

        exoPlayer.setPlayWhenReady(true);
    }

    mediaSession.setPlaybackState(stateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1).build());
    currentState = PlaybackStateCompat.STATE_PLAYING;

    refreshNotificationAndForegroundStatus(currentState);
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:35,代碼來源:PlayerService.java

示例14: configMediaPlayerState

private void configMediaPlayerState() {
    Log.i(TAG, "configMediaPlayerState audio focus = " + mFocusState);
    if (mFocusState == AUDIO_NO_FOCUS_NO_DUCK) {
        if (mPlaybackState == PlaybackStateCompat.STATE_PLAYING) {
            pause();
        }
    } else {
        if (mFocusState == AUDIO_NO_FOCUS_CAN_DUCK) {
            if (mPlayer != null) {
                mPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK);
            }
        } else {
            if (mPlayer != null) {
                mPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL);
            }
        }


        if (mPlayOnFocusGain) {
            if (mPlayer != null && !mPlayer.isPlaying()) {
                Log.d(TAG, "configMediaPlayerState startMediaPlayer. seeking to "
                        + getCurrentStreamPosition());

                if (mCurrentPosition == mPlayer.getCurrentPosition()) {
                    mPlayer.start();
                    mPlaybackState = PlaybackStateCompat.STATE_PLAYING;
                } else {
                    mPlayer.seekTo(mCurrentPosition);
                    mPlaybackState = PlaybackStateCompat.STATE_BUFFERING;
                }
            }
            mPlayOnFocusGain = false;
        }
    }
    if (mCallback != null) {
        mCallback.onPlayStateChanged(mPlaybackState);
    }
}
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:38,代碼來源:LocalPlayback.java

示例15: getNotification

public Notification getNotification(MediaMetadataCompat metadata,
                                    @NonNull PlaybackStateCompat state,
                                    MediaSessionCompat.Token token) {
    boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
    MediaDescriptionCompat description = metadata.getDescription();
    NotificationCompat.Builder builder =
            buildNotification(state, token, isPlaying, description);
    return builder.build();
}
 
開發者ID:nazmulidris,項目名稱:mediasession-mediaplayer,代碼行數:9,代碼來源:MediaNotificationManager.java


注:本文中的android.support.v4.media.session.PlaybackStateCompat.STATE_PLAYING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。