Java Code Examples for android.media.session.MediaSession#setFlags()

The following examples show how to use android.media.session.MediaSession#setFlags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicService.java    From android-music-player with Apache License 2.0 7 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

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

    final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this);

    mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() {
        @Override
        public void onPlaybackStatusChanged(PlaybackState state) {
            mSession.setPlaybackState(state);
            mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken());
        }
    });
}
 
Example 2
Source File: MusicService.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

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

    final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this);

    mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() {
        @Override
        public void onPlaybackStatusChanged(PlaybackState state) {
            mSession.setPlaybackState(state);
            mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken());
        }
    });
}
 
Example 3
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ApplicationLoader.postInitApplication();

    lastSelectedDialog = MessagesController.getNotificationsSettings(currentAccount).getInt("auto_lastSelectedDialog", 0);

    mediaSession = new MediaSession(this, "MusicService");
    setSessionToken(mediaSession.getSessionToken());
    mediaSession.setCallback(new MediaSessionCallback());
    mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    Context context = getApplicationContext();
    Intent intent = new Intent(context, LaunchActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession.setSessionActivity(pi);

    Bundle extras = new Bundle();
    extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
    mediaSession.setExtras(extras);

    updatePlaybackState(null);

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStarted);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
}
 
Example 4
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ApplicationLoader.postInitApplication();

    lastSelectedDialog = MessagesController.getNotificationsSettings(currentAccount).getInt("auto_lastSelectedDialog", 0);

    mediaSession = new MediaSession(this, "MusicService");
    setSessionToken(mediaSession.getSessionToken());
    mediaSession.setCallback(new MediaSessionCallback());
    mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    Context context = getApplicationContext();
    Intent intent = new Intent(context, LaunchActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession.setSessionActivity(pi);

    Bundle extras = new Bundle();
    extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
    mediaSession.setExtras(extras);

    updatePlaybackState(null);

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStarted);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
}
 
Example 5
Source File: WearBrowserService.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;
    mContext = this;
    mSession = new MediaSession(this, "WearBrowserService");
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

}
 
Example 6
Source File: ExoPlayerAudio.java    From ChannelSurfer with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mSession = new MediaSession(this, "ExoPlayerAudio");
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
 
Example 7
Source File: NotificationService.java    From RoMote with Apache License 2.0 5 votes vote down vote up
private void setUpMediaSession() {
    mediaSession = new MediaSession(this, TAG);
    mediaSession.setActive(true);
    mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setPlaybackState(
            new PlaybackState.Builder()
                    .setState(PlaybackState.STATE_PLAYING, 0L, 0F)
                    .setActions(PlaybackState.ACTION_PAUSE |
                            PlaybackState.ACTION_PLAY |
                            PlaybackState.ACTION_REWIND |
                            PlaybackState.ACTION_FAST_FORWARD)
                    .build());
    mediaSession.setMetadata(new MediaMetadata.Builder().build());
}
 
Example 8
Source File: MusicBrowserService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ApplicationLoader.postInitApplication();

    lastSelectedDialog = MessagesController.getNotificationsSettings(currentAccount).getInt("auto_lastSelectedDialog", 0);

    mediaSession = new MediaSession(this, "MusicService");
    setSessionToken(mediaSession.getSessionToken());
    mediaSession.setCallback(new MediaSessionCallback());
    mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    Context context = getApplicationContext();
    Intent intent = new Intent(context, LaunchActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession.setSessionActivity(pi);

    Bundle extras = new Bundle();
    extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
    mediaSession.setExtras(extras);

    updatePlaybackState(null);

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
}
 
Example 9
Source File: MusicBrowserService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ApplicationLoader.postInitApplication();

    lastSelectedDialog = MessagesController.getNotificationsSettings(currentAccount).getInt("auto_lastSelectedDialog", 0);

    mediaSession = new MediaSession(this, "MusicService");
    setSessionToken(mediaSession.getSessionToken());
    mediaSession.setCallback(new MediaSessionCallback());
    mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    Context context = getApplicationContext();
    Intent intent = new Intent(context, LaunchActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession.setSessionActivity(pi);

    Bundle extras = new Bundle();
    extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
    extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
    mediaSession.setExtras(extras);

    updatePlaybackState(null);

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
}