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


Java MediaSessionCompat.getController方法代码示例

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


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

示例1: from

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的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

示例2: MediaSessionConnector

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
/**
 * Creates an instance. Must be called on the same thread that is used to construct the player
 * instances passed to {@link #setPlayer(Player, PlaybackPreparer, CustomActionProvider...)}.
 *
 * @param mediaSession The {@link MediaSessionCompat} to connect to.
 * @param playbackController A {@link PlaybackController} for handling playback actions, or {@code
 *     null} if the connector should handle playback actions directly.
 * @param doMaintainMetadata Whether the connector should maintain the metadata of the session. If
 *     {@code false}, you need to maintain the metadata of the media session yourself (provide at
 *     least the duration to allow clients to show a progress bar).
 * @param metadataExtrasPrefix A string to prefix extra keys which are propagated from the active
 *     queue item to the session metadata.
 */
public MediaSessionConnector(
    MediaSessionCompat mediaSession,
    PlaybackController playbackController,
    boolean doMaintainMetadata,
    @Nullable String metadataExtrasPrefix) {
  this.mediaSession = mediaSession;
  this.playbackController = playbackController != null ? playbackController
      : new DefaultPlaybackController();
  this.metadataExtrasPrefix = metadataExtrasPrefix != null ? metadataExtrasPrefix : "";
  this.handler = new Handler(Looper.myLooper() != null ? Looper.myLooper()
      : Looper.getMainLooper());
  this.doMaintainMetadata = doMaintainMetadata;
  mediaSession.setFlags(BASE_MEDIA_SESSION_FLAGS);
  mediaController = mediaSession.getController();
  mediaSessionCallback = new MediaSessionCallback();
  exoPlayerEventListener = new ExoPlayerEventListener();
  customActionMap = Collections.emptyMap();
  commandMap = new HashMap<>();
  registerCommandReceiver(playbackController);
}
 
开发者ID:y20k,项目名称:transistor,代码行数:34,代码来源:MediaSessionConnector.java

示例3: notificationBuilder

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private NotificationCompat.Builder notificationBuilder(PlayerService context, MediaSessionCompat session) {
    MediaControllerCompat controller = session.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(mediaMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ART))
            .setContentIntent(clickIntent)
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, receiverName, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
开发者ID:SpongeBobSun,项目名称:Prodigal,代码行数:18,代码来源:NotificationUtil.java

示例4: createStopNotification

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public static void createStopNotification(MediaSessionCompat mediaSession, Service context, Class<?> serviceClass, int NOTIFICATION_ID) {

        PendingIntent stopIntent = PendingIntent
                .getService(context, 0, getIntent(MediaRecorderService.REQUEST_TYPE_STOP, context, serviceClass),
                        PendingIntent.FLAG_CANCEL_CURRENT);

        MediaControllerCompat controller = mediaSession.getController();
        MediaMetadataCompat mediaMetadata = controller.getMetadata();
        MediaDescriptionCompat description = mediaMetadata.getDescription();
        // Start foreground service to avoid unexpected kill
        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(description.getTitle())
                .setContentText(description.getSubtitle())
                .setSubText(description.getDescription())
                .setLargeIcon(description.getIconBitmap())
                .setDeleteIntent(stopIntent)
                // Add a pause button
                .addAction(new android.support.v7.app.NotificationCompat.Action(
                        R.drawable.ic_stop_black_24dp, context.getString(R.string.stop),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
                        .setMediaSession(mediaSession.getSessionToken())
                        .setShowActionsInCompactView(0)
                        .setShowCancelButton(true)
                        .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setSmallIcon(R.drawable.ic_album_black_24dp)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .build();

        context.startForeground(NOTIFICATION_ID, notification);
    }
 
开发者ID:aschober,项目名称:vinyl-cast,代码行数:34,代码来源:Helpers.java

示例5: onCreate

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int movieId = getActivity().getIntent().getIntExtra(EXTRA_MOVIE_ID, -1);
    if (movieId == -1) {
        Log.w(TAG, "Invalid movieId, cannot playback.");
        throw new IllegalArgumentException("Invalid movieId " + movieId);
    }

    mPlaylistAdapter =
            MockPlaylistAdapterFactory.createMoviePlaylistAdapterWithActiveMovieId(movieId);

    mSession = new MediaSessionCompat(getContext(), TAG);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setActive(true);
    MediaControllerCompat.setMediaController((Activity) getContext(), mSession.getController());

    mPlayerGlue =
            new PrimaryPlaybackControlsGlue<>(
                    getContext(),
                    new MediaPlayerAdapter(getContext()),
                    mSession.getController());
    mPlayerGlue.setHost(new VideoFragmentGlueHost(this));
    mPlayerGlue.addPlayerCallback(playWhenReadyPlayerCallback);
    mPlayerGlue.addPlayerCallback(playPausePlayerCallback);

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

    playMedia(mPlaylistAdapter.getCurrentItem());
}
 
开发者ID:googlesamples,项目名称:leanback-assistant,代码行数:35,代码来源:PlaybackFragment.java

示例6: from

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
/**
 * Build a notification using the information from the given media session.
 * @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.
 */
public static NotificationCompat.Builder from(Context context,
                                              MediaSessionCompat mediaSession,
                                              String channel) {

    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat description = mediaMetadata.getDescription();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channel);

    builder
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSubText(description.getDescription())
            .setContentIntent(controller.getSessionActivity())
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setWhen(0)
            .setShowWhen(false);

    if (description.getIconBitmap() == null || description.getIconBitmap().isRecycled()) {
        builder.setLargeIcon(
                BitmapFactory.decodeResource(context.getResources(), R.drawable.art_default));
    } else {
        builder.setLargeIcon(description.getIconBitmap());
    }

    return builder;
}
 
开发者ID:marverenic,项目名称:Jockey,代码行数:35,代码来源:MediaStyleHelper.java

示例7: buildNotification

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public static Notification buildNotification(Context context, MediaSessionCompat session) {

        MediaControllerCompat controller = session.getController();
        MediaMetadataCompat metadata = controller.getMetadata();
        PlaybackStateCompat playbackState = controller.getPlaybackState();

        if ((metadata == null) || (playbackState == null)) {
            return null;
        }

        boolean isPlaying = playbackState.getState() == PlaybackStateCompat.STATE_PLAYING;
        NotificationCompat.Action action = isPlaying ?
                new NotificationCompat.Action(android.R.drawable.ic_media_pause,
                        context.getString(R.string.pause),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_PAUSE)) :
                new NotificationCompat.Action(android.R.drawable.ic_media_play,
                        context.getString(R.string.play),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_PLAY));

        MediaDescriptionCompat description = metadata.getDescription();
        Bitmap albumArt = description.getIconBitmap();
        if (albumArt == null) {
            albumArt = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
        }


        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MusicService.NOTIFICATION_CHANNEL_ID);
        builder.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
//                .setShowActionsInCompactView(new int[]{0})
.setMediaSession(session.getSessionToken()))
                .addAction(action)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setShowWhen(false)
                .setContentIntent(controller.getSessionActivity())
                .setContentTitle(description.getTitle())
                .setContentText(description.getSubtitle())
                .setLargeIcon(albumArt)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

        return builder.build();
    }
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:44,代码来源:NotificationHelper.java

示例8: getBuilderCompat

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private NotificationCompat.Builder getBuilderCompat (Context context, PlayManager manager, @PlayService.State int state, Song song) {

        PendingIntent playPauseIt = getActionIntent(context, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
        PendingIntent previousIt = getActionIntent(context, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
        PendingIntent nextIt = getActionIntent(context, KeyEvent.KEYCODE_MEDIA_NEXT);
        PendingIntent deleteIntent = getActionIntent(context, KeyEvent.KEYCODE_MEDIA_STOP);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, PlayDetailActivity.class), 0);

        boolean isPlaying = manager.isPlaying();
        MediaSessionCompat sessionCompat = manager.getMediaSessionCompat();
        MediaControllerCompat controllerCompat = sessionCompat.getController();
        PendingIntent sessionActivity = controllerCompat.getSessionActivity();
        Log.v(TAG, "getBuilderCompat sessionActivity = " + sessionActivity);
        MediaDescriptionCompat descriptionCompat = controllerCompat.getMetadata().getDescription();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setContentTitle(descriptionCompat.getTitle());
        builder.setShowWhen(false);
        builder.setContentText(descriptionCompat.getSubtitle());
        builder.setSubText(descriptionCompat.getDescription());
        builder.setSmallIcon(R.drawable.ic_notification_queue_music);
        builder.addAction(R.drawable.ic_skip_previous, "previous", previousIt);
        builder.addAction(isPlaying ? R.drawable.ic_pause : R.drawable.ic_play, "play pause", playPauseIt);
        builder.addAction(R.drawable.ic_skip_next, "next", nextIt);
        builder.setContentIntent(contentIntent);
        builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        builder.setLargeIcon(descriptionCompat.getIconBitmap());
        NotificationCompat.MediaStyle mediaStyle = new NotificationCompat.MediaStyle();
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            builder.setOngoing(true);
            mediaStyle.setShowCancelButton(true);
            mediaStyle.setCancelButtonIntent(deleteIntent);
        } else {
            builder.setOngoing(isPlaying);
            builder.setDeleteIntent(deleteIntent);
        }
        mediaStyle.setShowActionsInCompactView(0, 1, 2);

        if (sessionCompat != null) {
            mediaStyle.setMediaSession(sessionCompat.getSessionToken());
        }
        builder.setStyle(mediaStyle);
        return builder;
    }
 
开发者ID:boybeak,项目名称:BeMusic,代码行数:45,代码来源:SimpleAgent.java


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