Example usage for android.support.v4.media.session MediaSessionCompat FLAG_HANDLES_TRANSPORT_CONTROLS

List of usage examples for android.support.v4.media.session MediaSessionCompat FLAG_HANDLES_TRANSPORT_CONTROLS

Introduction

In this page you can find the example usage for android.support.v4.media.session MediaSessionCompat FLAG_HANDLES_TRANSPORT_CONTROLS.

Prototype

int FLAG_HANDLES_TRANSPORT_CONTROLS

To view the source code for android.support.v4.media.session MediaSessionCompat FLAG_HANDLES_TRANSPORT_CONTROLS.

Click Source Link

Document

Sets this flag on the session to indicate that it handles transport control commands through its Callback .

Usage

From source file:com.doctoror.fuckoffmusicplayer.data.media.session.MediaSessionFactoryImpl.java

@NonNull
@Override/*from  ww w  .ja  v a2 s  . com*/
public MediaSessionCompat newMediaSession() {
    final MediaSessionCompat mediaSession = new MediaSessionCompat(context, TAG_MEDIA_SESSION,
            mediaButtonReceiver, mediaButtonIntent);
    mediaSession.setCallback(mediaSessionCallback);
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setSessionActivity(PendingIntent.getActivity(context, 1,
            new Intent(context, sessionActivityClass), PendingIntent.FLAG_UPDATE_CURRENT));
    mediaSession.setActive(true);
    return mediaSession;
}

From source file:com.devbrackets.android.exomedia.EMLockScreen.java

/**
 * Creates a new EMLockScreen object/*from w ww  .  j a  va  2s  .  com*/
 *
 * @param context The context to use for holding a MediaSession and sending action intents
 * @param mediaServiceClass The class for the service that owns the backing MediaService and to notify of playback actions
 */
public EMLockScreen(Context context, Class<? extends Service> mediaServiceClass) {
    this.context = context;
    this.mediaServiceClass = mediaServiceClass;

    ComponentName componentName = new ComponentName(context, MediaControlsReceiver.class.getName());

    mediaSession = new MediaSessionCompat(context, SESSION_TAG, componentName,
            getMediaButtonReceiverPendingIntent(componentName));
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(new SessionCallback());
}

From source file:com.devbrackets.android.playlistcore.helper.MediaControlsHelper.java

/**
 * Creates a new MediaControlsHelper object
 *
 * @param context The context to use for holding a MediaSession and sending action intents
 * @param mediaServiceClass The class for the service that owns the backing MediaService and to notify of playback actions
 */// w  ww .j a v a2 s . co m
public MediaControlsHelper(@NonNull Context context, @NonNull Class<? extends Service> mediaServiceClass) {
    this.context = context;

    ComponentName componentName = new ComponentName(context, MediaControlsReceiver.class.getName());

    mediaSession = new MediaSessionCompat(context, SESSION_TAG, componentName,
            getMediaButtonReceiverPendingIntent(componentName, mediaServiceClass));
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(new SessionCallback(mediaServiceClass));
}

From source file:org.gateshipone.odyssey.playbackservice.managers.PlaybackServiceStatusHelper.java

public PlaybackServiceStatusHelper(PlaybackService playbackService) {
    mPlaybackService = playbackService;/*from w  w  w . j  a v a  2s .c  om*/

    // Get MediaSession objects
    mMediaSession = new MediaSessionCompat(mPlaybackService, "OdysseyPBS");

    // Register the callback for the MediaSession
    mMediaSession.setCallback(new OdysseyMediaSessionCallback());

    mCoverLoader = new CoverBitmapLoader(mPlaybackService, new BitmapCoverListener());

    // Register the button receiver
    PendingIntent mediaButtonPendingIntent = PendingIntent.getBroadcast(mPlaybackService, 0,
            new Intent(mPlaybackService, RemoteControlReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
    mMediaSession.setMediaButtonReceiver(mediaButtonPendingIntent);
    mMediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS + MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    // Initialize the notification manager
    mNotificationManager = new OdysseyNotificationManager(mPlaybackService);
}

From source file:com.mylovemhz.simplay.MusicService.java

private void initialize() {
    trackQueue = new ArrayList<>();

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "music lock");

    ComponentName receiver = new ComponentName(getPackageName(), MediaButtonEventReceiver.class.getName());
    mediaSession = new MediaSessionCompat(this, TAG_MUSIC_SERVICE, receiver, null);
    mediaSession.setFlags(// w  w w. j av  a2  s.  c  o  m
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(new SimpleSessionCallback(this));

    currentState = State.IDLE;
    mediaSession.setActive(true);

    isInitialized = true;
    Log.d(TAG_MUSIC_SERVICE, "Initialized...");
}

From source file:com.classiqo.nativeandroid_32bitz.MusicService.java

@Override
public void onCreate() {
    super.onCreate();
    LogHelper.d(TAG, "onCreate");

    mMusicProvider = new MusicProvider();
    mMusicProvider.retrieveMediaAsync(null);
    mPackageValidator = new PackageValidator(this);

    QueueManager queueManager = new QueueManager(mMusicProvider, getResources(),
            new QueueManager.MetadataUpdateListener() {
                @Override/*from   w  ww.java2  s . co  m*/
                public void onMetadataChanged(MediaMetadataCompat metadata) {
                    mSession.setMetadata(metadata);
                }

                @Override
                public void onMetadataRetrieveError() {
                    mPlaybackManager.updatePlaybackState(getString(R.string.error_no_metadata));
                }

                @Override
                public void onCurrentQueueIndexUpdated(int queueIndex) {
                    mPlaybackManager.handlePlayRequest();
                }

                @Override
                public void onQueueUpdated(String title, List<MediaSessionCompat.QueueItem> newQueue) {
                    mSession.setQueue(newQueue);
                    mSession.setQueueTitle(title);
                }
            });

    LocalPlayback playback = new LocalPlayback(this, mMusicProvider);
    mPlaybackManager = new PlaybackManager(this, getResources(), mMusicProvider, queueManager, playback);

    mSession = new MediaSessionCompat(this, "MusicService");
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(mPlaybackManager.getMediaSessionCallback());
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

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

    mSessionExtras = new Bundle();
    //        CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
    //        WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
    //        SearHelper.setUseBackgroundFromTheme(mSessionExtras, true);
    mSession.setExtras(mSessionExtras);

    mPlaybackManager.updatePlaybackState(null);

    try {
        mMediaNotificationManager = new MediaNotificationManager(this);
    } catch (RemoteException e) {
        throw new IllegalStateException("Could not create a MediaNotificationManager", e);
    }

    //        if (!TvHelper.isTvUiMode(this)) {
    //            mCastSessionManager = CastContext.getSharedInstance(this).getSessionManager();
    //            mCastSessionManagerListener = new CastSessionManagerListener();
    //            mCastSessionManager.addSessionManagerListener(mCastSessionManagerListener, CastSession.class);
    //        }

    mMediaRouter = MediaRouter.getInstance(getApplicationContext());

    //        registerCarConnectionReceiver();
}

From source file:com.phearom.um.MusicService.java

@Override
public void onCreate() {
    super.onCreate();
    LogHelper.d(TAG, "onCreate");

    mMusicProvider = new MusicProvider(getApplicationContext());
    mMusicProvider.retrieveMediaAsync(null /* Callback */);

    mPackageValidator = new PackageValidator(this);
    QueueManager queueManager = new QueueManager(mMusicProvider, getResources(),
            new QueueManager.MetadataUpdateListener() {
                @Override//ww  w  .j a va  2s  . com
                public void onMetadataChanged(MediaMetadataCompat metadata) {
                    mSession.setMetadata(metadata);
                }

                @Override
                public void onMetadataRetrieveError() {
                    mPlaybackManager.updatePlaybackState(getString(R.string.error_no_metadata));
                }

                @Override
                public void onCurrentQueueIndexUpdated(int queueIndex) {
                    mPlaybackManager.handlePlayRequest();
                }

                @Override
                public void onQueueUpdated(String title, List<MediaSessionCompat.QueueItem> newQueue) {
                    mSession.setQueue(newQueue);
                    mSession.setQueueTitle(title);
                }
            });

    LocalPlayback playback = new LocalPlayback(this, mMusicProvider);
    mPlaybackManager = new PlaybackManager(this, getResources(), mMusicProvider, queueManager, playback);

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

    Context context = getApplicationContext();
    Intent intent = new Intent(context, NowPlayingActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setSessionActivity(pi);

    mSessionExtras = new Bundle();
    mSession.setExtras(mSessionExtras);

    mPlaybackManager.updatePlaybackState(null);

    try {
        mMediaNotificationManager = new MediaNotificationManager(this);
    } catch (RemoteException e) {
        throw new IllegalStateException("Could not create a MediaNotificationManager", e);
    }
}

From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java

@Override
public void onCreate() {
    // Create the service
    super.onCreate();

    restService = RESTService.getInstance();

    currentListPosition = 0;/* w w w . jav a 2 s . co  m*/

    mediaElementList = new ArrayList<>();

    // Setup media session
    mediaSessionCallback = new MediaSessionCallback();
    mediaSession = new MediaSessionCompat(this, "SMSPlayer");
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);
    mediaState = PlaybackStateCompat.STATE_NONE;
    updatePlaybackState();

    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sms");
    wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "sms");
}

From source file:github.popeen.dsub.util.compat.RemoteControlClientLP.java

@Override
public void register(Context context, ComponentName mediaButtonReceiverComponent) {
    downloadService = (DownloadService) context;
    mediaSession = new MediaSessionCompat(downloadService, "DSub MediaSession");

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0,
            mediaButtonIntent, 0);/*  w  w  w .  j  a  v a2s.c om*/
    mediaSession.setMediaButtonReceiver(mediaPendingIntent);

    Intent activityIntent = new Intent(context, SubsonicFragmentActivity.class);
    activityIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);
    mediaSession.setSessionActivity(activityPendingIntent);

    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
    mediaSession.setCallback(new EventCallback());

    mediaSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC);
    mediaSession.setActive(true);

    Bundle sessionExtras = new Bundle();
    sessionExtras.putBoolean(WEAR_BACKGROUND_THEME, true);
    sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_PREVIOUS, true);
    sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_NEXT, true);
    sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_PREVIOUS, true);
    sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_NEXT, true);
    mediaSession.setExtras(sessionExtras);

    imageLoader = SubsonicActivity.getStaticImageLoader(context);
}

From source file:com.example.android.leanback.PlaybackTransportControlGlueSample.java

/**
 * Public api to connect media session to this glue
 *///from   w w w  .  jav a  2  s  .co m
public void connectToMediaSession(MediaSessionCompat mediaSessionCompat) {
    mMediaSessionCompat = mediaSessionCompat;
    mMediaSessionCompat.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mMediaSessionCompat.setActive(true);
    mMediaSessionCompat.setCallback(new MediaSessionCallback());
    onMediaSessionMetaDataChanged();
}