Show hourglass icon when buffering
This commit is contained in:
parent
e08480f345
commit
c79997ebe3
|
@ -94,12 +94,7 @@ public final class NotificationUtil {
|
||||||
} else {
|
} else {
|
||||||
notificationBuilder.setLargeIcon(player.getThumbnail());
|
notificationBuilder.setLargeIcon(player.getThumbnail());
|
||||||
}
|
}
|
||||||
|
updateActions(notificationBuilder, player);
|
||||||
setAction(player, notificationSlot0, 0);
|
|
||||||
setAction(player, notificationSlot1, 1);
|
|
||||||
setAction(player, notificationSlot2, 2);
|
|
||||||
setAction(player, notificationSlot3, 3);
|
|
||||||
setAction(player, notificationSlot4, 4);
|
|
||||||
|
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||||
}
|
}
|
||||||
|
@ -122,7 +117,7 @@ public final class NotificationUtil {
|
||||||
private NotificationCompat.Builder createNotification(final VideoPlayerImpl player) {
|
private NotificationCompat.Builder createNotification(final VideoPlayerImpl player) {
|
||||||
notificationManager =
|
notificationManager =
|
||||||
(NotificationManager) player.context.getSystemService(NOTIFICATION_SERVICE);
|
(NotificationManager) player.context.getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context,
|
final NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context,
|
||||||
player.context.getString(R.string.notification_channel_id));
|
player.context.getString(R.string.notification_channel_id));
|
||||||
|
|
||||||
final String compactView = player.sharedPreferences.getString(player.context.getString(
|
final String compactView = player.sharedPreferences.getString(player.context.getString(
|
||||||
|
@ -165,6 +160,7 @@ public final class NotificationUtil {
|
||||||
new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT))
|
new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT))
|
||||||
.setColor(ContextCompat.getColor(player.context, R.color.gray))
|
.setColor(ContextCompat.getColor(player.context, R.color.gray))
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH);
|
.setPriority(NotificationCompat.PRIORITY_HIGH);
|
||||||
|
|
||||||
final boolean scaleImageToSquareAspectRatio = player.sharedPreferences.getBoolean(
|
final boolean scaleImageToSquareAspectRatio = player.sharedPreferences.getBoolean(
|
||||||
player.context.getString(R.string.scale_to_square_image_in_notifications_key),
|
player.context.getString(R.string.scale_to_square_image_in_notifications_key),
|
||||||
false);
|
false);
|
||||||
|
@ -174,22 +170,8 @@ public final class NotificationUtil {
|
||||||
builder.setLargeIcon(player.getThumbnail());
|
builder.setLargeIcon(player.getThumbnail());
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationSlot0 = player.sharedPreferences.getString(
|
initializeNotificationSlots(player);
|
||||||
player.context.getString(R.string.notification_slot_0_key), notificationSlot0);
|
updateActions(builder, player);
|
||||||
notificationSlot1 = player.sharedPreferences.getString(
|
|
||||||
player.context.getString(R.string.notification_slot_1_key), notificationSlot1);
|
|
||||||
notificationSlot2 = player.sharedPreferences.getString(
|
|
||||||
player.context.getString(R.string.notification_slot_2_key), notificationSlot2);
|
|
||||||
notificationSlot3 = player.sharedPreferences.getString(
|
|
||||||
player.context.getString(R.string.notification_slot_3_key), notificationSlot3);
|
|
||||||
notificationSlot4 = player.sharedPreferences.getString(
|
|
||||||
player.context.getString(R.string.notification_slot_4_key), notificationSlot4);
|
|
||||||
|
|
||||||
addAction(builder, player, notificationSlot0);
|
|
||||||
addAction(builder, player, notificationSlot1);
|
|
||||||
addAction(builder, player, notificationSlot2);
|
|
||||||
addAction(builder, player, notificationSlot3);
|
|
||||||
addAction(builder, player, notificationSlot4);
|
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
@ -224,32 +206,50 @@ public final class NotificationUtil {
|
||||||
// ACTIONS
|
// ACTIONS
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void addAction(final NotificationCompat.Builder builder,
|
private void initializeNotificationSlots(final VideoPlayerImpl player) {
|
||||||
final VideoPlayerImpl player,
|
notificationSlot0 = player.sharedPreferences.getString(
|
||||||
final String slot) {
|
player.context.getString(R.string.notification_slot_0_key), notificationSlot0);
|
||||||
builder.addAction(getAction(builder, player, slot));
|
notificationSlot1 = player.sharedPreferences.getString(
|
||||||
|
player.context.getString(R.string.notification_slot_1_key), notificationSlot1);
|
||||||
|
notificationSlot2 = player.sharedPreferences.getString(
|
||||||
|
player.context.getString(R.string.notification_slot_2_key), notificationSlot2);
|
||||||
|
notificationSlot3 = player.sharedPreferences.getString(
|
||||||
|
player.context.getString(R.string.notification_slot_3_key), notificationSlot3);
|
||||||
|
notificationSlot4 = player.sharedPreferences.getString(
|
||||||
|
player.context.getString(R.string.notification_slot_4_key), notificationSlot4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
private void setAction(final VideoPlayerImpl player,
|
private void updateActions(final NotificationCompat.Builder builder,
|
||||||
final String slot,
|
final VideoPlayerImpl player) {
|
||||||
final int slotNumber) {
|
builder.mActions.clear();
|
||||||
notificationBuilder.mActions.set(slotNumber, getAction(notificationBuilder, player, slot));
|
addAction(builder, player, notificationSlot0);
|
||||||
|
addAction(builder, player, notificationSlot1);
|
||||||
|
addAction(builder, player, notificationSlot2);
|
||||||
|
addAction(builder, player, notificationSlot3);
|
||||||
|
addAction(builder, player, notificationSlot4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationCompat.Action getAction(final NotificationCompat.Builder builder,
|
private void addAction(final NotificationCompat.Builder builder,
|
||||||
final VideoPlayerImpl player,
|
final VideoPlayerImpl player,
|
||||||
final String slot) {
|
final String slot) {
|
||||||
|
final NotificationCompat.Action action = getAction(player, slot);
|
||||||
|
if (action != null) {
|
||||||
|
builder.addAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private NotificationCompat.Action getAction(final VideoPlayerImpl player,
|
||||||
|
final String slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case "play_pause_buffering":
|
case "play_pause_buffering":
|
||||||
if (player.getCurrentState() == BasePlayer.STATE_PREFLIGHT
|
if (player.getCurrentState() == BasePlayer.STATE_PREFLIGHT
|
||||||
|| player.getCurrentState() == BasePlayer.STATE_BLOCKED
|
|| player.getCurrentState() == BasePlayer.STATE_BLOCKED
|
||||||
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING) {
|
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING) {
|
||||||
builder.setSmallIcon(android.R.drawable.stat_sys_download);
|
return getAction(player, R.drawable.ic_hourglass_top_white_24dp,
|
||||||
return getAction(player, R.drawable.ic_file_download_white_24dp,
|
|
||||||
"Buffering", ACTION_BUFFERING);
|
"Buffering", ACTION_BUFFERING);
|
||||||
} else {
|
} else {
|
||||||
builder.setSmallIcon(R.drawable.ic_newpipe_triangle_white);
|
|
||||||
return getAction(player,
|
return getAction(player,
|
||||||
player.isPlaying() ? R.drawable.exo_notification_pause
|
player.isPlaying() ? R.drawable.exo_notification_pause
|
||||||
: R.drawable.exo_notification_play,
|
: R.drawable.exo_notification_play,
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 302 B |
Binary file not shown.
After Width: | Height: | Size: 246 B |
Binary file not shown.
After Width: | Height: | Size: 413 B |
Binary file not shown.
After Width: | Height: | Size: 614 B |
Binary file not shown.
After Width: | Height: | Size: 777 B |
Loading…
Reference in New Issue