Audio Service Backup
Audio Service Backup
Audio Service Backup
Player;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.IBinder;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.widget.ProgressBar;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator;
import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.ui.PlayerNotificationManager;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.osman.cccr.InsideActivities.Predica_InsideActivity;
import com.osman.cccr.R;
import com.squareup.picasso.Picasso;
Predica_InsideActivity Pview;
@Override
public void onCreate() {
super.onCreate();
playerNotificationManager =
PlayerNotificationManager.createWithNotificationChannel(
context,
PLAYBACK_CHANNEL_ID,
R.string.playback_channel_name,
PLAYBACK_NOTIFICATION_ID,
new PlayerNotificationManager.MediaDescriptionAdapter() {
@Override
public String getCurrentContentTitle(Player player) {
return Pistas[player.getCurrentWindowIndex()].title;
}
@Nullable
@Override
public PendingIntent createCurrentContentIntent(Player player) {
return pendingIntent;
}
@Nullable
@Override
public String getCurrentContentText(Player player) {
return Pistas[player.getCurrentWindowIndex()].description;
}
@Nullable
@Override
public Bitmap getCurrentLargeIcon(Player player,
PlayerNotificationManager.BitmapCallback callback) {
return Tracks.getBitmap(
context,
Pistas[player.getCurrentWindowIndex()].bitmapResource);
}
}
);
playerNotificationManager.setNotificationListener(new
PlayerNotificationManager.NotificationListener() {
@Override
public void onNotificationStarted(int notificationId, Notification
notification) {
startForeground(notificationId, notification);
}
@Override
public void onNotificationCancelled(int notificationId) {
stopSelf();
}
});
playerNotificationManager.setPlayer(player);
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
@Override
public void onDestroy() {
mediaSession.release();
mediaSessionConnector.setPlayer(null, null);
playerNotificationManager.setPlayer(null);
player.release();
player = null;
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
}