notification ready
This commit is contained in:
parent
372db5e78d
commit
3221c95e04
1 changed files with 14 additions and 30 deletions
|
@ -2,7 +2,6 @@ package asgardius.page.s3manager;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.TaskStackBuilder;
|
|
||||||
|
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
|
@ -10,7 +9,6 @@ import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.PictureInPictureParams;
|
import android.app.PictureInPictureParams;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -70,8 +68,6 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
AppOpsManager appOpsManager;
|
AppOpsManager appOpsManager;
|
||||||
private PlayerNotificationManager playerNotificationManager;
|
private PlayerNotificationManager playerNotificationManager;
|
||||||
private int notificationId = 1234;
|
private int notificationId = 1234;
|
||||||
Intent playerIntent;
|
|
||||||
PendingIntent playerPendingIntent;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -84,12 +80,7 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
channel.setSound(null, null);
|
channel.setSound(null, null);
|
||||||
manager.createNotificationChannel(channel);
|
manager.createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
// Create an Intent for the activity you want to start
|
appOpsManager = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
|
||||||
playerIntent = new Intent(getApplicationContext(), VideoPlayer.class);
|
|
||||||
playerIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
// Get the PendingIntent containing the entire back stack
|
|
||||||
playerPendingIntent = PendingIntent.getActivity
|
|
||||||
(getApplicationContext(), 0, playerIntent, PendingIntent.FLAG_IMMUTABLE);
|
|
||||||
mediaSession = new MediaSessionCompat(this, getPackageName());
|
mediaSession = new MediaSessionCompat(this, getPackageName());
|
||||||
mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
||||||
hideSystemBars();
|
hideSystemBars();
|
||||||
|
@ -148,11 +139,7 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
//player.setMediaItem(mediaItem);
|
//player.setMediaItem(mediaItem);
|
||||||
// Prepare the player.
|
// Prepare the player.
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
//playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build();
|
playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build();
|
||||||
playerNotificationManager =
|
|
||||||
new PlayerNotificationManager.Builder(this, notificationId, "playback")
|
|
||||||
.setChannelImportance(NotificationManager.IMPORTANCE_HIGH)
|
|
||||||
.setMediaDescriptionAdapter(new DescriptionAdapter()).build();
|
|
||||||
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
|
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
|
||||||
playerNotificationManager.setPlayer(player);
|
playerNotificationManager.setPlayer(player);
|
||||||
player.setMediaSource(mediaSource);
|
player.setMediaSource(mediaSource);
|
||||||
|
@ -298,7 +285,7 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStop() {
|
/*public void onStop() {
|
||||||
try {
|
try {
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||||
&& this.getPackageManager()
|
&& this.getPackageManager()
|
||||||
|
@ -316,11 +303,11 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
simpleCache.release();
|
simpleCache.release();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void onResume(){
|
public void onResume(){
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -349,7 +336,7 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
@ -360,40 +347,37 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrentContentTitle(Player player) {
|
public String getCurrentContentTitle(Player player) {
|
||||||
//int window = player.getCurrentMediaItemIndex();
|
int window = player.getCurrentMediaItemIndex();
|
||||||
return getTitle().toString();
|
return getTitle().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getCurrentContentText(Player player) {
|
public String getCurrentContentText(Player player) {
|
||||||
//int window = player.getCurrentMediaItemIndex();
|
int window = player.getCurrentMediaItemIndex();
|
||||||
//return getCurrentContentText(player);
|
return getCurrentContentText(player);
|
||||||
return "Video Player";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Bitmap getCurrentLargeIcon(Player player,
|
public Bitmap getCurrentLargeIcon(Player player,
|
||||||
PlayerNotificationManager.BitmapCallback callback) {
|
PlayerNotificationManager.BitmapCallback callback) {
|
||||||
//int window = player.getCurrentMediaItemIndex();
|
int window = player.getCurrentMediaItemIndex();
|
||||||
//Bitmap largeIcon = getCurrentLargeIcon(player, callback);
|
Bitmap largeIcon = getCurrentLargeIcon(player, callback);
|
||||||
/*if (largeIcon == null && getLargeIconUri(window) != null) {
|
/*if (largeIcon == null && getLargeIconUri(window) != null) {
|
||||||
// load bitmap async
|
// load bitmap async
|
||||||
loadBitmap(getLargeIconUri(window), callback);
|
loadBitmap(getLargeIconUri(window), callback);
|
||||||
return getPlaceholderBitmap();
|
return getPlaceholderBitmap();
|
||||||
}*/
|
}*/
|
||||||
//return largeIcon;
|
return largeIcon;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public PendingIntent createCurrentContentIntent(Player player) {
|
public PendingIntent createCurrentContentIntent(Player player) {
|
||||||
//int window = player.getCurrentMediaItemIndex();
|
int window = player.getCurrentMediaItemIndex();
|
||||||
//return createPendingIntent(window);
|
//return createPendingIntent(window);
|
||||||
//return null;
|
return null;
|
||||||
return playerPendingIntent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue