本文整理汇总了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());
}
示例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.");
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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());
}
}
}
示例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();
}
}
}
示例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;
}
}
示例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();
}
示例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();
}
示例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));
}
}
});
}
示例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
}
}
}
});
}
示例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);
}
示例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();
}
示例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();
}