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


Java PlaybackState.getState方法代碼示例

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


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

示例1: setPlaybackState

import android.media.session.PlaybackState; //導入方法依賴的package包/類
public void setPlaybackState(PlaybackState playbackState) {
  if (playbackItem == null) {
    return;
  }

  playbackItem.updateAmountPlayed();

  int state = playbackState.getState();
  boolean isPlaying = state == PlaybackState.STATE_PLAYING;

  if (isPlaying) {
    Log.d(TAG, "Track playing");
    postEvent(playbackItem.getTrack());
    playbackItem.startPlaying();
    notificationManager.updateNowPlaying(playbackItem.getTrack());
    scheduleSubmission();
  } else {
    Log.d(TAG, String.format("Track paused (state %d)", state));
    postEvent(Track.empty());
    playbackItem.stopPlaying();
    notificationManager.removeNowPlaying();
    scrobbler.submit(playbackItem);
  }
}
 
開發者ID:peterjosling,項目名稱:scroball,代碼行數:25,代碼來源:PlayerState.java

示例2: updatePlaybackState

import android.media.session.PlaybackState; //導入方法依賴的package包/類
protected void updatePlaybackState(PlaybackState state) {
    if (mPlaybackControlsRow == null) {
        // We only update playback state after we get a valid metadata.
        return;
    }
    mLastPosition = state.getPosition();
    mLastPositionUpdateTime = state.getLastPositionUpdateTime();
    switch (state.getState()) {
        case PlaybackState.STATE_PLAYING:
            startProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
            break;
        case PlaybackState.STATE_PAUSED:
            stopProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
            break;
    }

    updatePlayListRow(getActivity().getMediaController().getQueue());
    mRowsAdapter.notifyArrayItemRangeChanged(
            mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:23,代碼來源:TvPlaybackFragment.java

示例3: getView

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowser.MediaItem item = getItem(position);
    int itemState = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        itemState = MediaItemViewHolder.STATE_PLAYABLE;
        MediaController controller = ((Activity) getContext()).getMediaController();
        if (controller != null && controller.getMetadata() != null) {
            String currentPlaying = controller.getMetadata().getDescription().getMediaId();
            String musicId = MediaIDHelper.extractMusicIDFromMediaID(
                    item.getDescription().getMediaId());
            if (currentPlaying != null && currentPlaying.equals(musicId)) {
                PlaybackState pbState = controller.getPlaybackState();
                if (pbState == null || pbState.getState() == PlaybackState.STATE_ERROR) {
                    itemState = MediaItemViewHolder.STATE_NONE;
                } else if (pbState.getState() == PlaybackState.STATE_PLAYING) {
                    itemState = MediaItemViewHolder.STATE_PLAYING;
                } else {
                    itemState = MediaItemViewHolder.STATE_PAUSED;
                }
            }
        }
    }
    return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
        item.getDescription(), itemState);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:27,代碼來源:MediaBrowserFragment.java

示例4: onClick

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
    PlaybackState stateObj = getActivity().getMediaController().getPlaybackState();
    final int state = stateObj == null ?
            PlaybackState.STATE_NONE : stateObj.getState();
    LogHelper.d(TAG, "Button pressed, in state " + state);
    switch (v.getId()) {
        case R.id.play_pause:
            LogHelper.d(TAG, "Play button pressed, in state " + state);
            if (state == PlaybackState.STATE_PAUSED ||
                    state == PlaybackState.STATE_STOPPED ||
                    state == PlaybackState.STATE_NONE) {
                playMedia();
            } else if (state == PlaybackState.STATE_PLAYING ||
                    state == PlaybackState.STATE_BUFFERING ||
                    state == PlaybackState.STATE_CONNECTING) {
                pauseMedia();
            }
            break;
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:22,代碼來源:PlaybackControlsFragment.java

示例5: connectToSession

import android.media.session.PlaybackState; //導入方法依賴的package包/類
private void connectToSession(MediaSession.Token token) {
    MediaController mediaController = new MediaController(FullScreenPlayerActivity.this, token);
    if (mediaController.getMetadata() == null) {
        finish();
        return;
    }
    setMediaController(mediaController);
    mediaController.registerCallback(mCallback);
    PlaybackState state = mediaController.getPlaybackState();
    updatePlaybackState(state);
    MediaMetadata metadata = mediaController.getMetadata();
    if (metadata != null) {
        updateMediaDescription(metadata.getDescription());
        updateDuration(metadata);
    }
    updateProgress();
    if (state != null && (state.getState() == PlaybackState.STATE_PLAYING ||
            state.getState() == PlaybackState.STATE_BUFFERING)) {
        scheduleSeekbarUpdate();
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:22,代碼來源:FullScreenPlayerActivity.java

示例6: getPlaybackState

import android.media.session.PlaybackState; //導入方法依賴的package包/類
private int getPlaybackState() {
	Activity activity = getActivity();

	if (activity != null) {
		PlaybackState state = activity.getMediaController().getPlaybackState();
		if (state != null) {
			return state.getState();
		} else {
			return PlaybackState.STATE_NONE;
		}
	}
	return PlaybackState.STATE_NONE;
}
 
開發者ID:NiciDieNase,項目名稱:chaosflix-leanback,代碼行數:14,代碼來源:OverlayFragment.java

示例7: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
	if (state.getState() != PlaybackState.STATE_NONE) {
		updateProgress();
	}
	onStateChanged();
}
 
開發者ID:NiciDieNase,項目名稱:chaosflix-leanback,代碼行數:8,代碼來源:PlaybackHelper.java

示例8: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    // Update your UI to reflect the new state. Do not change media playback here.
    if (DEBUG) Log.d(TAG, "Playback state changed: " + state.getState());

    int nextState = state.getState();
    if (nextState != PlaybackState.STATE_NONE) {
        updateProgress();
    }
    onStateChanged();
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:12,代碼來源:PlaybackControlHelper.java

示例9: getPlaybackState

import android.media.session.PlaybackState; //導入方法依賴的package包/類
private int getPlaybackState() {
    Activity activity = getActivity();

    if (activity != null) {
        PlaybackState state = activity.getMediaController().getPlaybackState();
        if (state != null) {
            return state.getState();
        } else {
            return PlaybackState.STATE_NONE;
        }
    }
    return PlaybackState.STATE_NONE;
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:14,代碼來源:PlaybackOverlayFragment.java

示例10: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onPlaybackStateChanged(PlaybackState state) {
    super.onPlaybackStateChanged(state);
    StandardWidget.currentlyPlaying = state.getState() == PlaybackState.STATE_PLAYING;
    updateMetadata();
    sendBroadcast(new Intent(StandardWidget.WIDGET_UPDATE));
}
 
開發者ID:jathak,項目名稱:musicwidget,代碼行數:8,代碼來源:NotificationListener.java

示例11: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    super.onPlaybackStateChanged(state);
    byte[] data = new byte[1];
    data[0] = (byte)(state.getState() == PlaybackState.STATE_PLAYING ?  1 : 0);
    mDevice.write(mediaPlayingCharac, data, MediaService.this);
}
 
開發者ID:AsteroidOS,項目名稱:AsteroidOSSync,代碼行數:8,代碼來源:MediaService.java

示例12: isMediaPlaying

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public boolean isMediaPlaying() {
    PlaybackState playbackState = mMediaController.getPlaybackState();
    if (playbackState == null) {
        return false;
    }
    int state = playbackState.getState();
    return state != PlaybackState.STATE_NONE && state != PlaybackState.STATE_CONNECTING
            && state != PlaybackState.STATE_PAUSED;
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:11,代碼來源:DvrPlaybackControlHelper.java

示例13: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    if (state.getState() == PlaybackState.STATE_PLAYING
            && mCurrentPlaybackState == PlaybackState.STATE_PLAYING) {
        startProgressAutomation();
        setFadingEnabled(true);
    } else if (state.getState() == PlaybackState.STATE_PLAYING) {
        mCurrentPlaybackState = PlaybackState.STATE_PLAYING;
        startProgressAutomation();
        setFadingEnabled(true);
        mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlayPauseAction.PAUSE));
        notifyChanged(mPlayPauseAction);
    } else if (state.getState() == PlaybackState.STATE_PAUSED
            && mCurrentPlaybackState != PlaybackState.STATE_PAUSED) {
        mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
        stopProgressAutomation();
        setFadingEnabled(false);
        mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlayPauseAction.PLAY));
        notifyChanged(mPlayPauseAction);
    }

    int currentTime;

    if (state.getState() == PlaybackState.STATE_PAUSED
            || state.getState() == PlaybackState.STATE_PLAYING) {
        currentTime = mPlaybackControlsRow.getCurrentTime();
    } else {
        currentTime = (int) state.getPosition();
    }
    mPlaybackControlsRow.setCurrentTime(currentTime);
    mPlaybackControlsRow.setBufferedProgress(currentTime + SIMULATED_BUFFERED_TIME);
}
 
開發者ID:hitherejoe,項目名稱:PictureInPicturePlayground,代碼行數:35,代碼來源:PlaybackOverlayFragment.java

示例14: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    LogHelper.d(TAG, "onPlaybackStateChanged, state=", state);
    if (mPlaybackFragment == null || state.getState() == PlaybackState.STATE_BUFFERING) {
        return;
    }
    mPlaybackFragment.updatePlaybackState(state);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:9,代碼來源:TvPlaybackActivity.java

示例15: onPlaybackStateChanged

import android.media.session.PlaybackState; //導入方法依賴的package包/類
private void onPlaybackStateChanged(PlaybackState state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null," +
                "this should not happen if the callback was properly unregistered. Ignoring.");
        return;
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
        case PlaybackState.STATE_PAUSED:
        case PlaybackState.STATE_STOPPED:
            enablePlay = true;
            break;
        case PlaybackState.STATE_ERROR:
            LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
            Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
            break;
    }

    if (enablePlay) {
        mPlayPause.setImageDrawable(
                getActivity().getDrawable(R.drawable.ic_play_arrow_black_36dp));
    } else {
        mPlayPause.setImageDrawable(getActivity().getDrawable(R.drawable.ic_pause_black_36dp));
    }

    MediaController controller = getActivity().getMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:40,代碼來源:PlaybackControlsFragment.java


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