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


Java PlaybackStateCompat.STATE_NONE屬性代碼示例

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


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

示例1: getDrawableByState

private Drawable getDrawableByState(Context context, int state) {
    switch (state) {
        case PlaybackStateCompat.STATE_NONE:
            Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play);
            DrawableCompat.setTintList(pauseDrawable, colorPlay);
            return pauseDrawable;
        case PlaybackStateCompat.STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.equalizer);
            DrawableCompat.setTintList(animation, colorPlay);
            animation.start();
            return animation;
        case PlaybackStateCompat.STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.equalizer);
            DrawableCompat.setTintList(playDrawable, colorPause);
            return playDrawable;
        default:
            Drawable noneDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play);
            DrawableCompat.setTintList(noneDrawable, colorPlay);
            return noneDrawable;
    }
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:21,代碼來源:AdapterMusic.java

示例2: getView

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowserCompat.MediaItem item = getItem(position);
    int itemState = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        String itemMediaId = item.getDescription().getMediaId();
        int playbackState = PlaybackStateCompat.STATE_NONE;
        if (mCurrentState != null) {
            playbackState = mCurrentState.getState();
        }
        if (mCurrentMetadata != null
                && itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
            if (playbackState == PlaybackStateCompat.STATE_PLAYING
                    || playbackState == PlaybackStateCompat.STATE_BUFFERING) {
                itemState = MediaItemViewHolder.STATE_PLAYING;
            } else if (playbackState != PlaybackStateCompat.STATE_ERROR) {
                itemState = MediaItemViewHolder.STATE_PAUSED;
            }
        }
    }
    return MediaItemViewHolder.setupView(
            (Activity) getContext(), convertView, parent, item.getDescription(), itemState);
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:23,代碼來源:MusicPlayerActivity.java

示例3: getView

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowserCompat.MediaItem item = getItem(position);
    int itemState = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        String itemMediaId = item.getDescription().getMediaId();
        int playbackState = PlaybackStateCompat.STATE_NONE;
        if (mCurrentState != null) {
            playbackState = mCurrentState.getState();
        }
        if (mCurrentMetadata != null
                && itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
            if (playbackState == PlaybackState.STATE_PLAYING
                    || playbackState == PlaybackState.STATE_BUFFERING) {
                itemState = MediaItemViewHolder.STATE_PLAYING;
            } else if (playbackState != PlaybackState.STATE_ERROR) {
                itemState = MediaItemViewHolder.STATE_PAUSED;
            }
        }
    }
    return MediaItemViewHolder.setupView(
            (Activity) getContext(), convertView, parent, item.getDescription(), itemState);
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:23,代碼來源:MusicPlayerActivity.java

示例4: playPause

@OnClick(R.id.play_pause)
public void playPause(){
    lastState=null;
    MediaControllerCompat controllerCompat=MediaControllerCompat.getMediaController(getActivity());
    PlaybackStateCompat stateCompat=controllerCompat.getPlaybackState();
    if(stateCompat!=null){
        MediaControllerCompat.TransportControls controls=
                controllerCompat.getTransportControls();
        switch (stateCompat.getState()){
            case PlaybackStateCompat.STATE_PLAYING:
            case PlaybackStateCompat.STATE_BUFFERING:
                controls.pause();
                break;
            case PlaybackStateCompat.STATE_NONE:
            case PlaybackStateCompat.STATE_PAUSED:
            case PlaybackStateCompat.STATE_STOPPED:
                controls.play();
                break;
            default:
                Log.d(TAG, "State "+stateCompat.getState());
        }
    }
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:23,代碼來源:TrackFragment.java

示例5: playbackStateToName

private String playbackStateToName(final int playbackState) {
    switch (playbackState) {
        case PlaybackStateCompat.STATE_NONE:
            return "STATE_NONE";
        case PlaybackStateCompat.STATE_STOPPED:
            return "STATE_STOPPED";
        case PlaybackStateCompat.STATE_PAUSED:
            return "STATE_PAUSED";
        case PlaybackStateCompat.STATE_PLAYING:
            return "STATE_PLAYING";
        case PlaybackStateCompat.STATE_FAST_FORWARDING:
            return "STATE_FAST_FORWARDING";
        case PlaybackStateCompat.STATE_REWINDING:
            return "STATE_REWINDING";
        case PlaybackStateCompat.STATE_BUFFERING:
            return "STATE_BUFFERING";
        case PlaybackStateCompat.STATE_ERROR:
            return "STATE_ERROR";
        case PlaybackStateCompat.STATE_CONNECTING:
            return "STATE_CONNECTING";
        case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS:
            return "STATE_SKIPPING_TO_PREVIOUS";
        case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT:
            return "STATE_SKIPPING_TO_NEXT";
        case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM:
            return "STATE_SKIPPING_TO_QUEUE_ITEM";
        default:
            return "!Unknown State!";
    }
}
 
開發者ID:googlesamples,項目名稱:android-media-controller,代碼行數:30,代碼來源:MediaAppControllerActivity.java

示例6: onClick

@Override
public void onClick(View v) {
    final int state =
            mCurrentState == null
                    ? PlaybackStateCompat.STATE_NONE
                    : mCurrentState.getState();
    if (state == PlaybackStateCompat.STATE_PAUSED
            || state == PlaybackStateCompat.STATE_STOPPED
            || state == PlaybackStateCompat.STATE_NONE) {

        if (mCurrentMetadata == null) {
            mCurrentMetadata =
                    MusicLibrary.getMetadata(
                            MusicPlayerActivity.this,
                            MusicLibrary.getMediaItems().get(0).getMediaId());
            updateMetadata(mCurrentMetadata);
        }

        // TODO: [5] Remove the following line for playback in a Service
        mPlaybackManager.play(mCurrentMetadata);

        // TODO: [5] Uncomment the following block for playback in a Service
        /*
        MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
                .getTransportControls()
                .playFromMediaId(
                        mCurrentMetadata.getDescription().getMediaId(), null);
        */
    } else {
        // TODO: [6] Remove the following line for playback in a Service
        mPlaybackManager.pause();

        // TODO: [6] Uncomment the following block for playback in a Service
        /*
        MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
                .getTransportControls()
                .pause();
        */
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:40,代碼來源:MusicPlayerActivity.java

示例7: onClick

@Override
public void onClick(View v) {
    final int state =
            mCurrentState == null
                    ? PlaybackStateCompat.STATE_NONE
                    : mCurrentState.getState();
    if (state == PlaybackState.STATE_PAUSED
            || state == PlaybackState.STATE_STOPPED
            || state == PlaybackState.STATE_NONE) {

        if (mCurrentMetadata == null) {
            mCurrentMetadata =
                    MusicLibrary.getMetadata(
                            MusicPlayerActivity.this,
                            MusicLibrary.getMediaItems().get(0).getMediaId());
            updateMetadata(mCurrentMetadata);
        }
        MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
                .getTransportControls()
                .playFromMediaId(
                        mCurrentMetadata.getDescription().getMediaId(), null);
    } else {
        MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
                .getTransportControls()
                .pause();
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:27,代碼來源:MusicPlayerActivity.java

示例8: onPlaybackStateChanged

@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
    mPlaybackState = state;
    Log.i(TAG, "onPlaybackStateChanged: received new play state : " + state);
    if (state.getState() == PlaybackStateCompat.STATE_STOPPED ||
            state.getState() == PlaybackStateCompat.STATE_NONE) {
        stopNotification();
    } else {
        Notification notification = buildNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }

}
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:15,代碼來源:NovaNotificationManager.java

示例9: Playback

public Playback(Context context) {
    this.mContext = context;
    this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "playback_lock");
    this.mState = PlaybackStateCompat.STATE_NONE;
}
 
開發者ID:AllThatSeries,項目名稱:react-native-streaming-audio-player,代碼行數:8,代碼來源:Playback.java

示例10: onPlaybackStateChanged

@Override
public void onPlaybackStateChanged(@NonNull PlaybackStateCompat state) {
    mPlaybackState = state;
    if (state.getState() == PlaybackStateCompat.STATE_STOPPED ||
            state.getState() == PlaybackStateCompat.STATE_NONE) {
        stopNotification();
    } else {
        Notification notification = createNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }
}
 
開發者ID:AllThatSeries,項目名稱:react-native-streaming-audio-player,代碼行數:13,代碼來源:MediaNotificationManager.java

示例11: updatePlaybackState

public void updatePlaybackState(PlaybackStateCompat playbackState){
    this.playbackState=playbackState;
    if(playbackState.getState()==PlaybackStateCompat.STATE_STOPPED||
            playbackState.getState()==PlaybackStateCompat.STATE_NONE){
        stopNotification();
    }else{
        updateNotification();
    }
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:9,代碼來源:TrackNotification.java

示例12: updatePlaybackState

@Override
public void updatePlaybackState(int state) {
    Logger.e("updatePlaybackState: ", "" + state);
    switch (state) {
        case PlaybackStateCompat.STATE_PLAYING:
            pgPlayPauseLayout.setVisibility(View.INVISIBLE);
            btn_play.Play();
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_PLAYING);
                notifyAdapter(currentSong);
            }
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            pgPlayPauseLayout.setVisibility(View.INVISIBLE);
            btn_play.Pause();
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_PAUSED);
                notifyAdapter(currentSong);
            }
            break;
        case PlaybackStateCompat.STATE_NONE:
            currentSong.setPlayState(PlaybackStateCompat.STATE_NONE);
            notifyAdapter(currentSong);
            break;
        case PlaybackStateCompat.STATE_STOPPED:
            pgPlayPauseLayout.setVisibility(View.INVISIBLE);
            btn_play.Pause();
            audioPg.setValue(0);
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_NONE);
                notifyAdapter(currentSong);
            }
            break;
        case PlaybackStateCompat.STATE_BUFFERING:
            pgPlayPauseLayout.setVisibility(View.VISIBLE);
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_NONE);
                notifyAdapter(currentSong);
            }
            break;
    }
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:42,代碼來源:MusicActivity.java

示例13: AudioPlaybackListener

public AudioPlaybackListener(Context context) {
    this.mContext = context;
    this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "dmAudioStreaming_Lock");
    this.mState = PlaybackStateCompat.STATE_NONE;
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:6,代碼來源:AudioPlaybackListener.java

示例14: update

public void update(
        MediaMetadataCompat metadata,
        PlaybackStateCompat state,
        MediaSessionCompat.Token token) {
    if (state == null
            || state.getState() == PlaybackStateCompat.STATE_STOPPED
            || state.getState() == PlaybackStateCompat.STATE_NONE) {
        mService.stopForeground(true);
        try {
            mService.unregisterReceiver(this);
        } catch (IllegalArgumentException ex) {
            // ignore receiver not registered
        }
        mService.stopSelf();
        return;
    }
    if (metadata == null) {
        return;
    }
    boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    MediaDescriptionCompat description = metadata.getDescription();

    notificationBuilder
            .setStyle(
                    new NotificationCompat.MediaStyle()
                            .setMediaSession(token)
                            .setShowActionsInCompactView(0, 1, 2))
            .setColor(
                    mService.getApplication().getResources().getColor(R.color.notification_bg))
            .setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setContentIntent(createContentIntent())
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
            .setOngoing(isPlaying)
            .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
            .setShowWhen(isPlaying)
            .setUsesChronometer(isPlaying);

    // If skip to next action is enabled
    if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(mPrevAction);
    }

    notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);

    // If skip to prev action is enabled
    if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(mNextAction);
    }

    Notification notification = notificationBuilder.build();

    if (isPlaying && !mStarted) {
        mService.startService(new Intent(mService.getApplicationContext(), MusicService.class));
        mService.startForeground(NOTIFICATION_ID, notification);
        mStarted = true;
    } else {
        if (!isPlaying) {
            mService.stopForeground(false);
            mStarted = false;
        }
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:67,代碼來源:MediaNotificationManager.java

示例15: updatePlaybackState

public void updatePlaybackState(PlaybackStateCompat stateCompat){
    if(stateCompat==null) return;
    lastState=stateCompat;
    updateRepeatMode(isActionApplied(stateCompat.getActions(),
            PlaybackStateCompat.ACTION_SET_REPEAT_MODE));
    updateShuffleMode(isActionApplied(stateCompat.getActions(),
            PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE_ENABLED));
    //check the state
    switch (stateCompat.getState()){
        case PlaybackStateCompat.STATE_PLAYING:
            playPause.setVisibility(VISIBLE);
            if(playPause.isPlay()){
                playPause.change(false,true);
            }
            startSeekBarUpdate();
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            // mControllers.setVisibility(VISIBLE);
            // mLoading.setVisibility(INVISIBLE);
            playPause.setVisibility(VISIBLE);
            if(!playPause.isPlay()){
                playPause.change(true,true);
            }
            stopSeekBarUpdate();
            break;
        case PlaybackStateCompat.STATE_NONE:
        case PlaybackStateCompat.STATE_STOPPED:
            playPause.setVisibility(VISIBLE);
            if(playPause.isPlay()){
                playPause.change(false,true);
            }
            stopSeekBarUpdate();
            break;
        case PlaybackStateCompat.STATE_BUFFERING:
            playPause.setVisibility(INVISIBLE);
            stopSeekBarUpdate();
            break;
        default:
            Log.d(TAG, "Unhandled state "+stateCompat.getState());
    }
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:41,代碼來源:TrackFragment.java


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