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


Java MediaSessionCompat.setPlaybackState方法代碼示例

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


在下文中一共展示了MediaSessionCompat.setPlaybackState方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: onCreate

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
    Log.d(TAG, "onCreate");
    super.onCreate();
    castSessionManager = CastContext.getSharedInstance(this).getSessionManager();

    // Create a MediaSessionCompat
    mediaSession = new MediaSessionCompat(this, TAG);

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

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

    // MySessionCallback() has methods that handle callbacks from a media controller
    mediaSession.setCallback(mediaSessionCallback);

    // Set the session's token so that client activities can communicate with it.
    setSessionToken(mediaSession.getSessionToken());
}
 
開發者ID:aschober,項目名稱:vinyl-cast,代碼行數:25,代碼來源:MediaRecorderService.java

示例4: onCreate

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    // Start a new MediaSession.
    mSession = new MediaSessionCompat(this, "MusicService");
    mSession.setCallback(mCallback);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    setSessionToken(mSession.getSessionToken());

    // TODO: Uncomment the following line to show a notification.
    final MediaNotificationManager mediaNotificationManager =
            new MediaNotificationManager(this);

    mPlayback =
            new PlaybackManager(
                    this,
                    new PlaybackManager.Callback() {
                        @Override
                        public void onPlaybackStatusChanged(PlaybackStateCompat state) {
                            mSession.setPlaybackState(state);

                            // TODO: Uncomment the following line to show a notification.
                            mediaNotificationManager.update(
                                    mPlayback.getCurrentMedia(), state, getSessionToken());
                        }
                    });
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:31,代碼來源:MusicService.java

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

示例6: createMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private MediaSessionCompat createMediaSession(Context context) {
    // create a media session
    MediaSessionCompat session = new MediaSessionCompat(context, LOG_TAG);
    session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    session.setPlaybackState(getPlaybackState());
    session.setCallback(new MediaSessionCallback());
    if (mStation != null) {
        session.setMetadata(getMetadata(context, mStation, null));
    }
    setSessionToken(session.getSessionToken());

    return session;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:14,代碼來源:PlayerService.java

示例7: createMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void createMediaSession() {
    ComponentName receiver = new ComponentName(context.getPackageName(), RemoteReceiver.class.getName());
    mediaSession = new MediaSessionCompat(context, "MusicService", receiver, null);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setPlaybackState(
            new PlaybackStateCompat.Builder()
                    .setState(PlaybackStateCompat.STATE_PLAYING, 0, 0)
                    .setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE)
                    .build()
    );

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.requestAudioFocus(focusChange -> {}, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    mediaSession.setActive(true);
}
 
開發者ID:Mavamaarten,項目名稱:vk_music_android,代碼行數:16,代碼來源:MusicNotificationManager.java

示例8: initMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
/**
 * Initiate a MediaSession to allow the Android system to interact with the player
 */
private void initMediaSession() {
    Timber.i("Initializing MediaSession");
    ComponentName mbrComponent = new ComponentName(mContext, MediaButtonReceiver.class.getName());
    MediaSessionCompat session = new MediaSessionCompat(mContext, TAG, mbrComponent, null);

    session.setCallback(new MediaSessionCallback(this));
    session.setSessionActivity(
            PendingIntent.getActivity(
                    mContext, 0,
                    LibraryActivity.newNowPlayingIntent(mContext)
                            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
                    PendingIntent.FLAG_CANCEL_CURRENT));

    session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    PlaybackStateCompat.Builder state = new PlaybackStateCompat.Builder()
            .setActions(PlaybackStateCompat.ACTION_PLAY
                    | PlaybackStateCompat.ACTION_PLAY_PAUSE
                    | PlaybackStateCompat.ACTION_SEEK_TO
                    | PlaybackStateCompat.ACTION_PAUSE
                    | PlaybackStateCompat.ACTION_SKIP_TO_NEXT
                    | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
                    | PlaybackStateCompat.ACTION_STOP)
            .setState(PlaybackStateCompat.STATE_NONE, 0, 0f);

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setClass(mContext, MediaButtonReceiver.class);
    PendingIntent mbrIntent = PendingIntent.getBroadcast(mContext, 0, mediaButtonIntent, 0);
    session.setMediaButtonReceiver(mbrIntent);

    session.setPlaybackState(state.build());
    session.setActive(true);

    mMediaSession = session;
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:40,代碼來源:MusicPlayer.java

示例9: createMediaSession

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private MediaSessionCompat createMediaSession(Context context) {
    // create a media session
    MediaSessionCompat session = new MediaSessionCompat(context, LOG_TAG);
    session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    session.setPlaybackState(createSessionPlaybackState());
    session.setCallback(new MediaSessionCallback());
    setSessionToken(session.getSessionToken());

    return session;
}
 
開發者ID:y20k,項目名稱:transistor,代碼行數:11,代碼來源:PlayerService.java

示例10: onCreate

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    // set the initial playback state
    playbackState = new PlaybackStateCompat.Builder()
            .setState(PlaybackStateCompat.STATE_NONE, 0, 1.0f)
            .build();

    // instantiate the media session
    mediaSession = new MediaSessionCompat(this, LOG_TAG);
    mediaSession.setCallback(mediaSessionCallback);
    mediaSession.setActive(true);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setPlaybackState(playbackState);

    // TODO needs to be tied in to requesting audio focus
    //get instance to AudioManager
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // instantiate and configure the media player
    initMusicPlayer();

    // instantiate the media controller
    try {
        mediaController = new MediaControllerCompat(this, mediaSession.getSessionToken());
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
開發者ID:theBoyMo,項目名稱:RadioPlayer,代碼行數:32,代碼來源:PlaybackService.java

示例11: setCLient

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
public void setCLient()
{
    MediaMetadataRetriever meta = new MediaMetadataRetriever();
    Log.d("current song","of client is "+Current_playing_song.gettitle());
try {
    meta.setDataSource(getBaseContext(), Current_playing_song.getSonguri());
}
catch (Exception e)
{
    e.printStackTrace();
    Toast.makeText(getBaseContext(),"Error in playing song",Toast.LENGTH_SHORT).show();
    playnext();
}
    byte [] b = meta.getEmbeddedPicture();
    Bitmap bitmap;
    if(b!=null)
    {
        bitmap = BitmapFactory.decodeByteArray(b,0,b.length);
    }
    else
    {
        bitmap  = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher,null) ;
    }
    ComponentName receiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
    mediaSession = new MediaSessionCompat(this, "MusicService", receiver, null);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
            .setState(PlaybackStateCompat.STATE_PLAYING, 0, 0)
            .setActions(  PlaybackStateCompat.ACTION_SEEK_TO |
                    PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
                    PlaybackStateCompat.ACTION_SKIP_TO_NEXT |
                    PlaybackStateCompat.ACTION_PLAY |
                    PlaybackStateCompat.ACTION_PAUSE |
                    PlaybackStateCompat.ACTION_STOP)
            .build());
    mediaSession.setMetadata(new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST,Current_playing_song.getartist())
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM,Current_playing_song.getalbum())
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE,Current_playing_song.gettitle())
            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION,Current_playing_song.getDuration())
            .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap)
            .putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
            .build());

    mediaSession.setActive(true);
}
 
開發者ID:mdnafiskhan,項目名稱:Mp3Player,代碼行數:48,代碼來源:MusicService.java

示例12: applyState

import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
public static void applyState(MediaSessionCompat session, PlaybackStateCompat playbackState) {
    session.setPlaybackState(playbackState);

    ensureTransportControls(session, playbackState);

}
 
開發者ID:Wojtechnology,項目名稱:Sunami,代碼行數:7,代碼來源:MediaSessionCompatHelper.java


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