Example usage for android.media.session PlaybackState getActiveQueueItemId

List of usage examples for android.media.session PlaybackState getActiveQueueItemId

Introduction

In this page you can find the example usage for android.media.session PlaybackState getActiveQueueItemId.

Prototype

public long getActiveQueueItemId() 

Source Link

Document

Get the id of the currently active item in the queue.

Usage

From source file:org.opensilk.video.tv.ui.playback.PlaybackControlsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PlaybackActivityComponent activityComponent = DaggerService.getDaggerComponent(getActivity());
    mComponent = activityComponent//w w  w. ja v  a2  s.c  o m
            .newPlaybackControlsComponent(new PlaybackControlsModule(getActivity(), this));
    mComponent.inject(this);

    setBackgroundType(BG_NONE);

    //init mediaController
    mMediaController = getActivity().getMediaController();
    mMediaController.registerCallback(mMediaControllerCallback);

    //init primary adapter
    ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
    mAdapter = new SparseArrayObjectAdapter(presenterSelector);

    //init controls row
    mControlsRowGlue = new PlaybackControlsGlue(getContext(), this, mMediaController);

    MediaMetadata mediaMetadata = mMediaController.getMetadata();
    if (mediaMetadata != null) {
        mControlsRowGlue.onMetadataChanged(mediaMetadata);
    }

    PlaybackState playbackState = mMediaController.getPlaybackState();
    if (playbackState != null) {
        mControlsRowGlue.onStateChanged(playbackState);
    }

    PlaybackControlsRowPresenter controlsRowPresenter = mControlsRowGlue.createControlsRowAndPresenter();
    PlaybackControlsRow controlsRow = mControlsRowGlue.getControlsRow();
    //        SparseArrayObjectAdapter secondaryActionsAdapter =
    //                new SparseArrayObjectAdapter(new ControlButtonPresenterSelector());
    //        secondaryActionsAdapter.set(5, new PlaybackControlsRow.ClosedCaptioningAction(getContext()));
    //        controlsRow.setSecondaryActionsAdapter(secondaryActionsAdapter);
    presenterSelector.addClassPresenter(PlaybackControlsRow.class, controlsRowPresenter);
    mAdapter.set(CONTROLS_ROW, controlsRow);

    //init overview row
    mOverviewRow = new PlaybackOverviewRow(new HeaderItem("Overview"));
    PlaybackOverviewRowPresenter overviewRowPresenter = new PlaybackOverviewRowPresenter();
    if (playbackState != null) {
        updateOverview(playbackState.getActiveQueueItemId());
    }
    presenterSelector.addClassPresenter(PlaybackOverviewRow.class, overviewRowPresenter);
    mAdapter.set(OVERVIEW_ROW, mOverviewRow);
    Subscription overviewSub = mOverviewObservable.subscribe(info -> {
        mOverviewRow.setItem(info);
    }, e -> {
        Timber.w("videoDescription");
    });
    mSubscriptions.add(overviewSub);

    //init queue row
    QueueAdapter queueRowAdapter = new QueueAdapter();
    List<MediaSession.QueueItem> queue = mMediaController.getQueue();
    if (queue != null) {
        queueRowAdapter.swap(queue);
    }
    CharSequence queueTitle = mMediaController.getQueueTitle();
    if (StringUtils.isEmpty(queueTitle)) {
        queueTitle = "Queue";
    }
    mQueueRow = new ListRow(new HeaderItem(queueTitle.toString()), queueRowAdapter);
    presenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
    mAdapter.set(QUEUE_ROW, mQueueRow);

    //init subtitle row
    SubtitleAdapter subtitleAdapter = new SubtitleAdapter();
    mSubtitleRow = new ListRow(new HeaderItem("Subtitles"), subtitleAdapter);
    //not adding yet

    //set adapter
    setAdapter(mAdapter);
    setOnItemViewClickedListener(new ItemClickListener());

    //on new items update the activity result
    Subscription resultSub = mMediaItemObservable.subscribe(item -> {
        Activity activity = getActivity();
        if (activity != null) {
            Intent result = new Intent().putExtra(DetailsActivity.MEDIA_ITEM, item);
            activity.setResult(Activity.RESULT_FIRST_USER + 12, result);
        }
    }, e -> {
        Timber.w(e, "setResult()");
    });
    mSubscriptions.add(resultSub);
}