当前位置: 首页>>代码示例>>Java>>正文


Java MediaControllerCompat.getMediaController方法代码示例

本文整理汇总了Java中android.support.v4.media.session.MediaControllerCompat.getMediaController方法的典型用法代码示例。如果您正苦于以下问题:Java MediaControllerCompat.getMediaController方法的具体用法?Java MediaControllerCompat.getMediaController怎么用?Java MediaControllerCompat.getMediaController使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.media.session.MediaControllerCompat的用法示例。


在下文中一共展示了MediaControllerCompat.getMediaController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
public void onConnected() {
    if (isDetached()) {
        return;
    }

    mMediaId = getMediaId();

    if (mMediaId == null) {
        mMediaId = mMediaFragmentListener.getMediaBrowser().getRoot();
    }

    Log.d(TAG, mMediaId);

    // A bug will occurred if the mediaId already has a subscriber on this MediaBrowser instance
    // So unsubscribe first
    mMediaFragmentListener.getMediaBrowser().unsubscribe(mMediaId);
    mMediaFragmentListener.getMediaBrowser().subscribe(mMediaId, mSubscriptionCallback);

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    if (controller != null) {
        controller.registerCallback(mMediaControllerCallback);
    }
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:24,代码来源:BrowserFragment.java

示例2: playPause

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@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,代码行数:24,代码来源:TrackFragment.java

示例3: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
public void onConnected()
{
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    LogHelper.e(TAG, "onConnected, mediaController==null? ", controller == null);
    if (controller != null) {
        controller.registerCallback(mCallback);
        onPlaybackStateChanged(controller.getPlaybackState());
        onMetadataChanged(controller.getMetadata());

        PlaybackStateCompat state = controller.getPlaybackState();
        updatePlaybackState(state);
        MediaMetadataCompat metadata = controller.getMetadata();
        if (metadata != null) {
            updateMediaDescription(metadata.getDescription());
            updateDuration(metadata);
        }
        updateProgress();
        if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
                state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
            scheduleSeekbarUpdate();
        }
    }
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:24,代码来源:PlaybackControlsFragment.java

示例4: shouldShowControls

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
 * Check if the MediaSession is active and in a "playback-able" state
 * (not NONE and not STOPPED).
 *
 * @return true if the MediaSession's state requires playback controls to be visible.
 */
protected boolean shouldShowControls()
{
    LogHelper.e(TAG, "shouldShowControls");
    MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);
    if (mediaController == null ||
            mediaController.getMetadata() == null ||
            mediaController.getPlaybackState() == null) {
        return false;
    }
    switch (mediaController.getPlaybackState().getState()) {
        case PlaybackStateCompat.STATE_ERROR:
        case PlaybackStateCompat.STATE_NONE:
        case PlaybackStateCompat.STATE_STOPPED:
            return false;
        default:
            return true;
    }
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:25,代码来源:MainActivity.java

示例5: onClick

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onClick(DialogInterface dialog, int i) {

    if (mSelectIndex == i) {
        dialog.dismiss();
        return;
    }
    mSelectIndex = i;

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());

    if (controller != null) {
        controller.getTransportControls().sendCustomAction(
                StraasMediaCore.COMMAND_SET_FORMAT_INDEX, Utils.setNewFormatIndex(
                        mFormats.indexOf(mIncreasingBandwidthFormats[i])));
    }

    dialog.dismiss();
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:20,代码来源:SwitchQualityDialog.java

示例6: isMediaItemPlaying

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
 * Determine if media item is playing (matches the currently playing media item).
 *
 * @param context for retrieving the {@link MediaControllerCompat}
 * @param mediaItem to compare to currently playing {@link MediaBrowserCompat.MediaItem}
 * @return boolean indicating whether media item matches currently playing media item
 */
public static boolean isMediaItemPlaying(Activity context, MediaBrowserCompat.MediaItem mediaItem) {
    // Media item is considered to be playing or paused based on the controller's current
    // media id
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(context);
    if (controller != null && controller.getMetadata() != null) {
        String currentPlayingMediaId = controller.getMetadata().getDescription()
                .getMediaId();
        String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(
                mediaItem.getDescription().getMediaId());
        if (currentPlayingMediaId != null
                && TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:24,代码来源:MediaIDHelper.java

示例7: shouldShowControls

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
 * Check if the MediaSession is active and in a "playback-able" state
 * (not NONE and not STOPPED).
 *
 * @return true if the MediaSession's state requires playback controls to be visible.
 */
protected boolean shouldShowControls() {
    MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);
    if (mediaController == null ||
        mediaController.getMetadata() == null ||
        mediaController.getPlaybackState() == null) {
        return false;
    }
    switch (mediaController.getPlaybackState().getState()) {
        case PlaybackStateCompat.STATE_ERROR:
        case PlaybackStateCompat.STATE_NONE:
        case PlaybackStateCompat.STATE_STOPPED:
            return false;
        default:
            return true;
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:23,代码来源:BaseActivity.java

示例8: initializeWithMediaId

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
public void initializeWithMediaId(String mediaId) {
    LogHelper.d(TAG, "subscribeToData");
    // fetch browsing information to fill the listview:
    mMediaBrowser = mMediaFragmentListener.getMediaBrowser();

    if (mediaId == null) {
        mediaId = mMediaBrowser.getRoot();
    }

    subscribeToMediaId(mediaId, mSubscriptionCallback);

    // Add MediaController callback so we can redraw the list when metadata changes:
    MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(getActivity());
    if (mediaController != null) {
        mediaController.registerCallback(mMediaControllerCallback);
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:18,代码来源:TvBrowseFragment.java

示例9: updatePlaybackState

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
protected void updatePlaybackState(PlaybackStateCompat 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 PlaybackStateCompat.STATE_PLAYING:
            startProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            stopProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
            break;
    }

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    updatePlayListRow(controller.getQueue());
    mRowsAdapter.notifyArrayItemRangeChanged(
            mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:24,代码来源:TvPlaybackFragment.java

示例10: onItemClicked

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object clickedItem,
                          RowPresenter.ViewHolder rowViewHolder, Row row) {

    if (clickedItem instanceof MediaSessionCompat.QueueItem) {
        LogHelper.d(TAG, "item: ", clickedItem.toString());

        MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
        MediaSessionCompat.QueueItem item = (MediaSessionCompat.QueueItem) clickedItem;
        if (!QueueHelper.isQueueItemPlaying(getActivity(), item)
                || controller.getPlaybackState().getState()
                != PlaybackStateCompat.STATE_PLAYING) {
            controller.getTransportControls().skipToQueueItem(item.getQueueId());
        }
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:17,代码来源:TvPlaybackFragment.java

示例11: onItemClicked

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                          RowPresenter.ViewHolder rowViewHolder, Row row) {

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    if (controller == null) {
        return;
    }
    MediaControllerCompat.TransportControls controls = controller.getTransportControls();
    MediaBrowserCompat.MediaItem mediaItem = (MediaBrowserCompat.MediaItem) item;

    if (!MediaIDHelper.isMediaItemPlaying(getActivity(), mediaItem)) {
        controls.playFromMediaId(mediaItem.getMediaId(), null);
    }

    Intent intent = new Intent(getActivity(), TvPlaybackActivity.class);
    Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
            getActivity(),
            ((ImageCardView) itemViewHolder.view).getMainImageView(),
            TvVerticalGridActivity.SHARED_ELEMENT_NAME).toBundle();

    getActivity().startActivity(intent, bundle);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:24,代码来源:TvVerticalGridFragment.java

示例12: onClick

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    PlaybackStateCompat stateObj = controller.getPlaybackState();
    final int state = stateObj == null ?
            PlaybackStateCompat.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 == PlaybackStateCompat.STATE_PAUSED ||
                    state == PlaybackStateCompat.STATE_STOPPED ||
                    state == PlaybackStateCompat.STATE_NONE) {
                playMedia();
            } else if (state == PlaybackStateCompat.STATE_PLAYING ||
                    state == PlaybackStateCompat.STATE_BUFFERING ||
                    state == PlaybackStateCompat.STATE_CONNECTING) {
                pauseMedia();
            }
            break;
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:23,代码来源:PlaybackControlsFragment.java

示例13: onStop

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onStop() {
    super.onStop();
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(this);
    if (controller != null) {
        controller.unregisterCallback(mMediaControllerCallback);
    }
    if (mMediaBrowser != null && mMediaBrowser.isConnected()) {
        if (mCurrentMetadata != null) {
            mMediaBrowser.unsubscribe(mCurrentMetadata.getDescription().getMediaId());
        }
        mMediaBrowser.disconnect();
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:15,代码来源:MusicPlayerActivity.java

示例14: onStop

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
protected void onStop() {
    super.onStop();
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(this);
    if (controller != null) {
        controller.unregisterCallback(mMediaControllerCallback);
    }

    mMediaBrowser.disconnect();
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:11,代码来源:MainActivity.java

示例15: onMediaItemSelected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onMediaItemSelected(MediaBrowserCompat.MediaItem item) {
    if (item.isPlayable()) {
        MediaControllerCompat controller = MediaControllerCompat.getMediaController(this);
        MediaControllerCompat.TransportControls controls = controller.getTransportControls();

        controls.playFromMediaId(item.getMediaId(), null);
    } else if (item.isBrowsable()) {
        summitFragment(item.getMediaId());
    }
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:12,代码来源:MainActivity.java


注:本文中的android.support.v4.media.session.MediaControllerCompat.getMediaController方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。