List of usage examples for android.support.v4.media.session MediaSessionCompat FLAG_HANDLES_MEDIA_BUTTONS
int FLAG_HANDLES_MEDIA_BUTTONS
To view the source code for android.support.v4.media.session MediaSessionCompat FLAG_HANDLES_MEDIA_BUTTONS.
Click Source Link
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MediaSessionCompat mediaSession = new MediaSessionCompat(this, getApplication().getPackageName()); mediaSession.setCallback(mMediaSessionCallback); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mediaSession.setActive(true);/* ww w . j ava 2s . co m*/ PlaybackStateCompat state = new PlaybackStateCompat.Builder().setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS).build(); mediaSession.setPlaybackState(state); }
From source file:com.doctoror.fuckoffmusicplayer.data.media.session.MediaSessionFactoryImpl.java
@NonNull @Override// www . j av a 2 s . c om 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 ww w . j a va2s . 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 *///from w w w. j a va 2 s .c o 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;//w w w . j a v a2s. c o m // 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:org.interactiverobotics.headset_launcher.MediaButtonMonitorService.java
@Override public void onCreate() { Log.d(TAG, "Create"); // ? //w w w. j a v a 2 s . co m mMediaButtonReceiver = new ComponentName(this, MediaButtonReceiver.class); // , ? API 18+ // // final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); // // mediaButtonIntent.setComponent(mMediaButtonReceiver); // // mPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); mMediaSession = new MediaSessionCompat(this, TAG, mMediaButtonReceiver, /* pendingIntent */ null); mMediaSession.setCallback(new MediaSessionCompat.Callback() { @Override public boolean onMediaButtonEvent(Intent mediaButtonEvent) { if (Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonEvent.getAction())) { final KeyEvent keyEvent = (KeyEvent) mediaButtonEvent .getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (KeyEvent.KEYCODE_HEADSETHOOK == keyEvent.getKeyCode()) { if (KeyEvent.ACTION_DOWN == keyEvent.getAction()) { Log.d(TAG, "Media button down!"); // ? startService(new Intent(MediaButtonMonitorService.this, LauncherService.class)); } } else { Log.e(TAG, "Unknown keycode: " + keyEvent.getKeyCode()); } } else { Log.e(TAG, "Unknown intent: " + mediaButtonEvent.getAction()); } return true; } }); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mMediaSession.setActive(true); }
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 a va2 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// w w w.j a v a 2 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 v a 2s . c o 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); // 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;//from w w w. ja v a2 s.c om 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"); }