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


Java MediaControllerCompat类代码示例

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


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

示例1: initializeMediaSession

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
private void initializeMediaSession() {
    mSession = new MediaSessionCompat(this, TAG);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setActive(true);
    MediaControllerCompat.setMediaController(this, mSession.getController());

    MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mMovieView.getTitle())
            .build();
    mSession.setMetadata(metadata);

    MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(mMovieView);
    mSession.setCallback(mMediaSessionCallback);

    int state =
            mMovieView.isPlaying()
                    ? PlaybackStateCompat.STATE_PLAYING
                    : PlaybackStateCompat.STATE_PAUSED;
    updatePlaybackState(
            state,
            MEDIA_ACTIONS_ALL,
            mMovieView.getCurrentPosition(),
            mMovieView.getVideoResourceId());
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:27,代码来源:MediaSessionPlaybackActivity.java

示例2: startSessionActivity

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
private void startSessionActivity(MediaControllerCompat mediaController) {
    PendingIntent intent = mediaController.getSessionActivity();
    if (intent != null) {
        try {
            intent.send();
            return;
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
            Log.e(TAG, e.toString());
        }
    }
    Log.w(TAG, "Failed to open app by session activity.");
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:14,代码来源:MediaAppControllerActivity.java

示例3: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
@Override
public void onConnected() {
    mMediaBrowser.subscribe(mMediaBrowser.getRoot(), mSubscriptionCallback);
    try {
        MediaControllerCompat mediaController =
                new MediaControllerCompat(
                        MusicPlayerActivity.this, mMediaBrowser.getSessionToken());
        updatePlaybackState(mediaController.getPlaybackState());
        updateMetadata(mediaController.getMetadata());
        mediaController.registerCallback(mMediaControllerCallback);
        MediaControllerCompat.setMediaController(
                MusicPlayerActivity.this, mediaController);
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:17,代码来源:MusicPlayerActivity.java

示例4: from

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
/**
 * Build a notification using the information from the given media session. Makes heavy use
 * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
 *
 * @param context      Context used to construct the notification.
 * @param mediaSession Media session to get information.
 * @return A pre-built notification with information from the given media session.
 */
static NotificationCompat.Builder from(
        Context context, MediaSessionCompat mediaSession) {
    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat description = mediaMetadata.getDescription();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSubText(description.getDescription())
            .setLargeIcon(description.getIconBitmap())
            .setContentIntent(controller.getSessionActivity())
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
开发者ID:SergeyVinyar,项目名称:AndroidAudioExample,代码行数:27,代码来源:MediaStyleHelper.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: connectToSession

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException
{
    LogHelper.e(TAG, "connectToSession");
    MediaControllerCompat mediaController = new MediaControllerCompat(this, token);
    MediaControllerCompat.setMediaController(this, mediaController);

    mediaController.registerCallback(mMediaControllerCallback);

    if (shouldShowControls()) {
        showPlaybackControls();
    } else {
        LogHelper.e(TAG, "connectionCallback.onConnected: hiding controls because metadata is null");
        hidePlaybackControls();
    }

    if (mControlsFragment != null) {
        mControlsFragment.onConnected();
    }

    onMediaControllerConnected();
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:22,代码来源:MainActivity.java

示例10: connect

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
/**
 * public
 */
void connect(@NonNull ConnectionEventCallback callback) {
  disposeOnDestroy(EventBus.get()
      .listen(MediaBrowserRequestEvent.class)
      .subscribeOn(getSubscribeScheduler())
      .observeOn(getObserveScheduler())
      .subscribe(mediaBrowserRequestEvent -> handleSubscriptionRequest(
          mediaBrowserRequestEvent.subscribed()),
          throwable -> Timber.e(throwable, "Error subscription request bus")));

  disposeOnDestroy(EventBus.get()
      .listen(MediaControllerConnectionEvent.class)
      .subscribeOn(getSubscribeScheduler())
      .observeOn(getObserveScheduler())
      .subscribe(mediaControllerConnectionEvent -> {
        MediaControllerCompat controller = mediaControllerConnectionEvent.controller();
        if (controller == null) {
          callback.onDisconnected();
        } else {
          callback.onConnected(controller);
        }
      }, throwable -> Timber.e(throwable, "Error media controller bus")));
  interactor.connect();
}
 
开发者ID:pyamsoft,项目名称:dontsuck-mp,代码行数:27,代码来源:MainPresenter.java

示例11: getVideoQualityInfo

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
/**
 * Retrieve all video {@link Format} and current selected index from current media playback.
 * <p>
 * Later you could use {@link MediaControllerCompatHelper#setVideoQualityIndex(Activity, int)}
 * or {@link MediaControllerCompatHelper#setVideoQualityIndex(MediaControllerCompat, int)} to
 * change new index.
 */
public static void getVideoQualityInfo(@NonNull MediaControllerCompat controller,
                                       @NonNull final VideoQualityInfoCallback callback) {
    controller.sendCommand(StraasMediaCore.COMMAND_GET_VIDEO_FORMATS, null,
            new ResultReceiver(new Handler()) {
                @Override
                protected void onReceiveResult(int resultCode, Bundle resultData) {
                    resultData.setClassLoader(Format.class.getClassLoader());
                    if (resultData.containsKey(StraasMediaCore.KEY_CURRENT_VIDEO_FORMAT_INDEX)) {
                        ArrayList<Format> formats = resultData.getParcelableArrayList(StraasMediaCore.KEY_ALL_VIDEO_FORMATS);
                        int selectedIndex = resultData.getInt(StraasMediaCore.KEY_CURRENT_VIDEO_FORMAT_INDEX);
                        callback.onGetVideoQualityInfo(new VideoQualityInfo(formats, selectedIndex));
                    }
                }
            });
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:23,代码来源:MediaControllerCompatHelper.java

示例12: bind

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
public void bind(final MediaItem item) {
    mTitle.setText(item.getDescription().getTitle());
    mSubtitle.setText(item.getDescription().getDescription());
    if (item.getDescription().getIconUri() != null) {
        Glide.with(mIcon.getContext()).load(item.getDescription().getIconUri()).into(mIcon);
    }
    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity(v));
            if (controller != null) {
                if (item.isPlayable()) {
                    controller.getTransportControls().playFromMediaId(item.getMediaId(), null);
                } else if (item.isBrowsable()) {
                    //    TODO

                }
            }
        }
    });
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:22,代码来源:StraasPlayerActivity.java

示例13: PlayerControl

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
public PlayerControl(@NonNull MediaControllerCompat mediaControllerCompat, final MediaController mediaController) {
    mMediaControllerCompat = mediaControllerCompat;
    mCallback = new MediaControllerCompat.Callback() {
        @Override
        public void onPlaybackStateChanged(PlaybackStateCompat state) {
            processPlaybackState(state, mediaController);
        }

        @Override
        public void onMetadataChanged(MediaMetadataCompat metadata) {
            mLastMediaMetadataCompat = metadata;
        }
    };
    mMediaControllerCompat.registerCallback(mCallback);
    mLastMediaMetadataCompat = mMediaControllerCompat.getMetadata();
    processPlaybackState(mMediaControllerCompat.getPlaybackState(), mediaController);
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:18,代码来源:PlayerControl.java

示例14: 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

示例15: onUnbind

import android.support.v4.media.session.MediaControllerCompat; //导入依赖的package包/类
@Override
public void onUnbind(StraasMediaCore client) {
    mIsBind = false;
    mStraasMediaCore = client;

    MediaControllerCompat mediaControllerCompat = getMediaControllerCompat();
    if (mediaControllerCompat != null) {
        mediaControllerCompat.unregisterCallback(mMediaControllerCallback);
    }
    if (mContentSeekBar != null) {
        mContentSeekBar.destroy();
    }
    mCanToggleControllerUi = false;

    showControllerUi();
    showPlayUi();
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:18,代码来源:StraasPlayerView.java


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