當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaSessionCompat.setActive方法代碼示例

本文整理匯總了Java中android.support.v4.media.session.MediaSessionCompat.setActive方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaSessionCompat.setActive方法的具體用法?Java MediaSessionCompat.setActive怎麽用?Java MediaSessionCompat.setActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.media.session.MediaSessionCompat的用法示例。


在下文中一共展示了MediaSessionCompat.setActive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUpRemoteControlClient

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void setUpRemoteControlClient() {
    final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(mMediaButtonReceiverComponent);

    mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    mMediaSession = new MediaSessionCompat(getApplication(), "TAG", mMediaButtonReceiverComponent, null);
    mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    PlaybackStateCompat playbackStateCompat = new PlaybackStateCompat.Builder()
            .setActions(
                    PlaybackStateCompat.ACTION_SEEK_TO |
                            PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
                            PlaybackStateCompat.ACTION_SKIP_TO_NEXT |
                            PlaybackStateCompat.ACTION_PLAY |
                            PlaybackStateCompat.ACTION_PAUSE |
                            PlaybackStateCompat.ACTION_STOP
            )
            .setState(isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, position(), 1.0f)
            .build();

    mMediaSession.setPlaybackState(playbackStateCompat);
    mMediaSession.setCallback(mMediaSessionCallback);
    mMediaSession.setActive(true);
    updateRemoteControlClient(META_CHANGED);
    mTransportController = mMediaSession.getController().getTransportControls();

}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:27,代碼來源:MusicPlaybackService.java

示例2: initializeMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void initializeMediaSession() {
    mMediaSession = new MediaSessionCompat(getContext(), TAG);
    mMediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
                    MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mMediaSession.setMediaButtonReceiver(null);
    mStateBuilder = new PlaybackStateCompat.Builder()
            .setActions(
                    PlaybackStateCompat.ACTION_PLAY |
                            PlaybackStateCompat.ACTION_PAUSE |
                            PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
                            PlaybackStateCompat.ACTION_PLAY_PAUSE);

    mMediaSession.setPlaybackState(mStateBuilder.build());
    mMediaSession.setCallback(new MySessionCallback());
    mMediaSession.setActive(true);
}
 
開發者ID:twisstosin,項目名稱:UdacityBakingAndroid,代碼行數:19,代碼來源:StepFragment.java

示例3: createMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private MediaSessionCompat createMediaSession() {
    Context context = getContext();
    MediaSessionCompat mediaSession =
            new MediaSessionCompat(context, context.getString(R.string.app_name),
                    new ComponentName(context, getButtonReceiverClass()), null);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mMediaSessionCallback);

    // TODO(mlamouri): the following code is to work around a bug that hopefully
    // MediaSessionCompat will handle directly. see b/24051980.
    try {
        mediaSession.setActive(true);
    } catch (NullPointerException e) {
        // Some versions of KitKat do not support AudioManager.registerMediaButtonIntent
        // with a PendingIntent. They will throw a NullPointerException, in which case
        // they should be able to activate a MediaSessionCompat with only transport
        // controls.
        mediaSession.setActive(false);
        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mediaSession.setActive(true);
    }
    return mediaSession;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:25,代碼來源:MediaNotificationManager.java

示例4: initializeMediaSession

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

示例5: createMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private MediaSessionCompat createMediaSession() {
    MediaSessionCompat mediaSession = new MediaSessionCompat(
            mContext,
            mContext.getString(R.string.app_name),
            new ComponentName(mContext.getPackageName(),
                    getButtonReceiverClassName()),
            null);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mMediaSessionCallback);

    // TODO(mlamouri): the following code is to work around a bug that hopefully
    // MediaSessionCompat will handle directly. see b/24051980.
    try {
        mediaSession.setActive(true);
    } catch (NullPointerException e) {
        // Some versions of KitKat do not support AudioManager.registerMediaButtonIntent
        // with a PendingIntent. They will throw a NullPointerException, in which case
        // they should be able to activate a MediaSessionCompat with only transport
        // controls.
        mediaSession.setActive(false);
        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mediaSession.setActive(true);
    }
    return mediaSession;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:27,代碼來源:MediaNotificationManager.java

示例6: doOpenSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void doOpenSession() {
    final ComponentName mediaButtonReceiver = new ComponentName(mContext,
            MediaButtonReceiver.class);

    final PendingIntent broadcastIntent = PendingIntent
            .getBroadcast(mContext, 1, new Intent(mContext, MediaButtonReceiver.class),
                    PendingIntent.FLAG_UPDATE_CURRENT);

    final MediaSessionCompat mediaSession = new MediaSessionCompat(mContext, TAG,
            mediaButtonReceiver, broadcastIntent);

    mediaSession.setCallback(new MediaSessionCallback(mContext));
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setActive(true);
    mediaSession.setSessionActivity(PendingIntent.getActivity(mContext, 1,
            new Intent(mContext, NowPlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));

    mMediaSession = mediaSession;

    Handlers.runOnIoThread(() -> reportMediaAndState(mediaSession));
}
 
開發者ID:Doctoror,項目名稱:PainlessMusicPlayer,代碼行數:23,代碼來源:MediaSessionHolder.java

示例7: initMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
void initMediaSession() {
    // NOTE: all this is so that when you press pause/play in the app, we can capture the
    // media control event, so that other apps DON'T (ie, google play music, plex, etc).
    // ideally we could do something useful with this, but for not, just eat it.

    try {
        ComponentName mediaButtonReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
        mediaSessionCompat = new MediaSessionCompat(getApplicationContext(), "SAGETVMINICLIENT", mediaButtonReceiver, null);
        mediaSessionCompat.setCallback(new MediaSessionCompat.Callback() {
            @Override
            public void onCommand(String command, Bundle extras, ResultReceiver cb) {
                log.debug("Audio Session Callback Handler: Command {}", command);
            }
        });
        mediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);

        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setClass(this, MediaButtonReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
        mediaSessionCompat.setMediaButtonReceiver(pendingIntent);
        mediaSessionCompat.setActive(true);
        log.debug("Media Session is setup to capture pause/play. session: "+mediaSessionCompat.getSessionToken());
    } catch (Throwable t) {
        log.error("Failed to capture the media session", t);
    }
}
 
開發者ID:OpenSageTV,項目名稱:sagetv-miniclient,代碼行數:27,代碼來源:MiniClientGDXActivity.java

示例8: setupMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
/**
 * 初始化並激活MediaSession
 */
private void setupMediaSession() {
    mMediaSession = new MediaSessionCompat(context, TAG);
    mMediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
                    MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS
    );
    mMediaSession.setCallback(callback);
    mMediaSession.setActive(true);
}
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:13,代碼來源:MediaSessionManager.java

示例9: onCreate

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMediaPlayerGlue = new PlaybackBannerControlGlue<MediaPlayerAdapter>(getContext(),
            new int[]{1}, new MediaPlayerAdapter(getContext())) {
        @Override
        public long getSupportedActions() {
            return PlaybackBannerControlGlue.ACTION_PLAY_PAUSE
                    | PlaybackBannerControlGlue.ACTION_SKIP_TO_NEXT
                    | PlaybackBannerControlGlue.ACTION_SKIP_TO_PREVIOUS;
        }
    };
    mMediaPlayerGlue.setHost(mHost);

    Bundle args = getArguments();
    mSelectedClip = args.getParcelable(PlaybackActivity.EXTRA_CLIP);
    mProgress = args.getLong(PlaybackActivity.EXTRA_PROGRESS);

    mMediaPlayerGlue.setTitle(mSelectedClip.getTitle());
    mMediaPlayerGlue.setSubtitle(mSelectedClip.getDescription());
    mMediaPlayerGlue.getPlayerAdapter().setDataSource(Uri.parse(mSelectedClip.getVideoUrl()));
    mSession = new MediaSessionCompat(getContext(), "TvLauncherSampleApp");
    mSession.setActive(true);
    mSession.setCallback(new MediaSessionCallback());
    playWhenReady();
    updatePlaybackState();
    updateMetadata(mSelectedClip);
}
 
開發者ID:googlesamples,項目名稱:leanback-homescreen-channels,代碼行數:29,代碼來源:VideoFragment.java

示例10: initializeMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void initializeMediaSession() {
    // Create a MediaSessionCompat.
    mMediaSession = new MediaSessionCompat(getContext(), StepDetailFragment.class.getSimpleName());

    // Enable callbacks from MediaButtons and TransportControls.
    mMediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
                    MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    // Do not let MediaButtons restart the player when the app is not visible.
    mMediaSession.setMediaButtonReceiver(null);

    // Set an initial PlaybackState with ACTION_PLAY, so media buttons can start the player.
    mStateBuilder = new PlaybackStateCompat.Builder()
            .setActions(
                    PlaybackStateCompat.ACTION_PLAY |
                            PlaybackStateCompat.ACTION_PAUSE |
                            PlaybackStateCompat.ACTION_PLAY_PAUSE);

    mMediaSession.setPlaybackState(mStateBuilder.build());


    // MySessionCallback has methods that handle callbacks from a media controller.
    mMediaSession.setCallback(new MediaSessionCallback());

    // Start the Media Session since the activity is active.
    mMediaSession.setActive(true);

}
 
開發者ID:harrynp,項目名稱:BakingApp,代碼行數:30,代碼來源:StepDetailFragment.java

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

示例12: mediaLockscreen

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void mediaLockscreen() {
    mediaSessionLockscreen = new MediaSessionCompat(this, TAG);
    mediaSessionLockscreen.setCallback(new MediaSessionCompat.Callback() {
        @Override
        public void onPlay() {
            play();
        }

        @Override
        public void onPause() {
            pause();
        }

        @Override
        public void onSkipToNext() {
            playnext(true);
        }

        @Override
        public void onSkipToPrevious() {
            playprev(true);
        }

        @Override
        public void onStop() {
            stopSelf();
        }

        @Override
        public void onSeekTo(long pos) {
            seekto((int) pos);
        }

        @Override
        public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
            if (mediaButtonReceiver != null) {
                mediaButtonReceiver.onReceive(MusicXService.this, mediaButtonEvent);
            }
            return true;
        }
    });
    mediaSessionLockscreen.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    ComponentName buttonCom = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.setComponent(buttonCom);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSessionLockscreen.setMediaButtonReceiver(pendingIntent);
    mediaSessionLockscreen.setActive(true);
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:51,代碼來源:MusicXService.java

示例13: setUpMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
/**
 * 初始化mediasession
 */
private void setUpMediaSession() {
    //初始化MediaSesson 用於監聽線控操作
    mMediaSession = new MediaSessionCompat(getApplicationContext(),"APlayer");
    mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mMediaSession.setCallback(new SessionCallBack());
    mMediaSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC);
    mMediaSession.setActive(true);
}
 
開發者ID:rRemix,項目名稱:APlayer,代碼行數:13,代碼來源:MusicService.java

示例14: initMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void initMediaSession() {
  FragmentActivity activity = getActivity();
  mediaSession = new MediaSessionCompat(activity, TAG);
  mediaSession.setCallback(new MediaSessionCallback());
  mediaSession.setFlags(FLAG_HANDLES_MEDIA_BUTTONS | FLAG_HANDLES_TRANSPORT_CONTROLS);
  mediaSession.setActive(true);
  setPlaybackState(STATE_NONE);
  activity.setSupportMediaController(mediaSession.getController());
}
 
開發者ID:mkjensen,項目名稱:danish-media-license,代碼行數:10,代碼來源:PlaybackFragment.java

示例15: setUpMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void setUpMediaSession() {
    mediaSession = new MediaSessionCompat(this, TAG, null, null);

    try {
        //mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mediaSession.setActive(true);
    } catch (NullPointerException ex) {
    }
}
 
開發者ID:wseemann,項目名稱:RoMote,代碼行數:10,代碼來源:NotificationService.java


注:本文中的android.support.v4.media.session.MediaSessionCompat.setActive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。