當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。