I use ExoPlayer with standard PlayerNotificationManager class from library.
When I close my app that playing music with swipe, Android fully kill it, music stopped, notification continues to be displayed, but buttons isn't active. Can I implement playing foreground without using Android Service? And if yes, how to do it? Maybe ExoPlayer have standard Service that allows to implement it?
Player initialization:
SimpleExoPlayer exoPlayer = new SimpleExoPlayer.Builder(context, new DefaultRenderersFactory(context))
.setTrackSelector(new DefaultTrackSelector(context))
.build();
exoPlayer.setAudioAttributes(audioAttributes);
exoPlayer.setHandleAudioBecomingNoisy(true);
MediaSessionCompat mediaSession = new MediaSessionCompat(context, "Newtone");
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
mediaSessionConnector.setPlayer(exoPlayer);
PlayerNotificationManager notificationManager = PlayerNotificationManager
.createWithNotificationChannel(
context, NOTIFICATION_CHANNEL_ID, R.string.app_name, R.string.app_name, NOTIFICATION_ID,
mediaDescriptionAdapter, notificationListener);
notificationManager.setPlayer(exoPlayer);
notificationManager.setMediaSessionToken(mediaSession.getSessionToken());
notificationManager.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
notificationManager.setUseNavigationActionsInCompactView(true);
notificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
notificationManager.setUseChronometer(false);
notificationManager.setFastForwardIncrementMs(0);
notificationManager.setRewindIncrementMs(0);