-Changed baseplayer metadata getters to use media tag as source.

-Changed background player notification to no longer update bitmap on progress time change.
-Changed popup player to move above soft keyboard when it is opened.
This commit is contained in:
John Zhen Mo 2018-06-26 10:16:54 -07:00
parent e7d23176b7
commit aa1878c15a
3 changed files with 46 additions and 25 deletions

View file

@ -199,7 +199,6 @@ public final class BackgroundPlayer extends Service {
remoteViews.setTextViewText(R.id.notificationSongName, basePlayerImpl.getVideoTitle()); remoteViews.setTextViewText(R.id.notificationSongName, basePlayerImpl.getVideoTitle());
remoteViews.setTextViewText(R.id.notificationArtist, basePlayerImpl.getUploaderName()); remoteViews.setTextViewText(R.id.notificationArtist, basePlayerImpl.getUploaderName());
remoteViews.setImageViewBitmap(R.id.notificationCover, basePlayerImpl.getThumbnail());
remoteViews.setOnClickPendingIntent(R.id.notificationPlayPause, remoteViews.setOnClickPendingIntent(R.id.notificationPlayPause,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT)); PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT));
@ -295,10 +294,22 @@ public final class BackgroundPlayer extends Service {
// Thumbnail Loading // Thumbnail Loading
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
private void updateNotificationThumbnail() {
if (notRemoteView != null) {
notRemoteView.setImageViewBitmap(R.id.notificationCover,
basePlayerImpl.getThumbnail());
}
if (bigNotRemoteView != null) {
bigNotRemoteView.setImageViewBitmap(R.id.notificationCover,
basePlayerImpl.getThumbnail());
}
}
@Override @Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage); super.onLoadingComplete(imageUri, view, loadedImage);
resetNotification(); resetNotification();
updateNotificationThumbnail();
updateNotification(-1); updateNotification(-1);
} }
@ -306,13 +317,7 @@ public final class BackgroundPlayer extends Service {
public void onLoadingFailed(String imageUri, View view, FailReason failReason) { public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
super.onLoadingFailed(imageUri, view, failReason); super.onLoadingFailed(imageUri, view, failReason);
resetNotification(); resetNotification();
updateNotification(-1); updateNotificationThumbnail();
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
super.onLoadingCancelled(imageUri, view);
resetNotification();
updateNotification(-1); updateNotification(-1);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -395,6 +400,7 @@ public final class BackgroundPlayer extends Service {
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) { protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
super.onMetadataChanged(tag); super.onMetadataChanged(tag);
resetNotification(); resetNotification();
updateNotificationThumbnail();
updateNotification(-1); updateNotification(-1);
updateMetadata(); updateMetadata();
} }
@ -525,6 +531,7 @@ public final class BackgroundPlayer extends Service {
public void onPlaying() { public void onPlaying() {
super.onPlaying(); super.onPlaying();
resetNotification(); resetNotification();
updateNotificationThumbnail();
updateNotification(R.drawable.ic_pause_white); updateNotification(R.drawable.ic_pause_white);
lockManager.acquireWifiAndCpu(); lockManager.acquireWifiAndCpu();
} }
@ -533,6 +540,7 @@ public final class BackgroundPlayer extends Service {
public void onPaused() { public void onPaused() {
super.onPaused(); super.onPaused();
resetNotification(); resetNotification();
updateNotificationThumbnail();
updateNotification(R.drawable.ic_play_arrow_white); updateNotification(R.drawable.ic_play_arrow_white);
lockManager.releaseWifiAndCpu(); lockManager.releaseWifiAndCpu();
} }
@ -547,6 +555,7 @@ public final class BackgroundPlayer extends Service {
if (notRemoteView != null) { if (notRemoteView != null) {
notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false); notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false);
} }
updateNotificationThumbnail();
updateNotification(R.drawable.ic_replay_white); updateNotification(R.drawable.ic_replay_white);
lockManager.releaseWifiAndCpu(); lockManager.releaseWifiAndCpu();
} }

View file

@ -1044,17 +1044,17 @@ public abstract class BasePlayer implements
@NonNull @NonNull
public String getVideoUrl() { public String getVideoUrl() {
return currentItem == null ? context.getString(R.string.unknown_content) : currentItem.getUrl(); return currentMetadata == null ? context.getString(R.string.unknown_content) : currentMetadata.getMetadata().getUrl();
} }
@NonNull @NonNull
public String getVideoTitle() { public String getVideoTitle() {
return currentItem == null ? context.getString(R.string.unknown_content) : currentItem.getTitle(); return currentMetadata == null ? context.getString(R.string.unknown_content) : currentMetadata.getMetadata().getName();
} }
@NonNull @NonNull
public String getUploaderName() { public String getUploaderName() {
return currentItem == null ? context.getString(R.string.unknown_content) : currentItem.getUploader(); return currentMetadata == null ? context.getString(R.string.unknown_content) : currentMetadata.getMetadata().getUploaderName();
} }
@Nullable @Nullable

View file

@ -98,6 +98,11 @@ public final class PopupVideoPlayer extends Service {
private static final int MINIMUM_SHOW_EXTRA_WIDTH_DP = 300; private static final int MINIMUM_SHOW_EXTRA_WIDTH_DP = 300;
private static final int IDLE_WINDOW_FLAGS = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
private static final int ONGOING_PLAYBACK_WINDOW_FLAGS = IDLE_WINDOW_FLAGS |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
private WindowManager windowManager; private WindowManager windowManager;
private WindowManager.LayoutParams windowLayoutParams; private WindowManager.LayoutParams windowLayoutParams;
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
@ -194,13 +199,11 @@ public final class PopupVideoPlayer extends Service {
final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ?
WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_PHONE :
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
final int interactiveInputMethodLayout = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
windowLayoutParams = new WindowManager.LayoutParams( windowLayoutParams = new WindowManager.LayoutParams(
(int) popupWidth, (int) getMinimumVideoHeight(popupWidth), (int) popupWidth, (int) getMinimumVideoHeight(popupWidth),
layoutParamType, layoutParamType,
interactiveInputMethodLayout, IDLE_WINDOW_FLAGS,
PixelFormat.TRANSLUCENT); PixelFormat.TRANSLUCENT);
windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP; windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
@ -249,11 +252,15 @@ public final class PopupVideoPlayer extends Service {
setRepeatModeRemote(notRemoteView, playerImpl.getRepeatMode()); setRepeatModeRemote(notRemoteView, playerImpl.getRepeatMode());
return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
.setOngoing(true) .setOngoing(true)
.setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setSmallIcon(R.drawable.ic_newpipe_triangle_white)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContent(notRemoteView); .setContent(notRemoteView);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
builder.setPriority(NotificationCompat.PRIORITY_MAX);
}
return builder;
} }
/** /**
@ -372,6 +379,12 @@ public final class PopupVideoPlayer extends Service {
} }
} }
private void updateWindowFlags(final int flags) {
if (windowLayoutParams == null || windowManager == null || playerImpl == null) return;
windowLayoutParams.flags = flags;
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
protected class VideoPlayerImpl extends VideoPlayer implements View.OnLayoutChangeListener { protected class VideoPlayerImpl extends VideoPlayer implements View.OnLayoutChangeListener {
@ -684,16 +697,15 @@ public final class PopupVideoPlayer extends Service {
@Override @Override
public void onPlaying() { public void onPlaying() {
super.onPlaying(); super.onPlaying();
updateWindowFlags(ONGOING_PLAYBACK_WINDOW_FLAGS);
resetNotification(); resetNotification();
updateNotification(R.drawable.ic_pause_white); updateNotification(R.drawable.ic_pause_white);
videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white); videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white);
hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME); hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
startForeground(NOTIFICATION_ID, notBuilder.build()); startForeground(NOTIFICATION_ID, notBuilder.build());
lockManager.acquireWifiAndCpu(); lockManager.acquireWifiAndCpu();
} }
@ -708,15 +720,15 @@ public final class PopupVideoPlayer extends Service {
@Override @Override
public void onPaused() { public void onPaused() {
super.onPaused(); super.onPaused();
updateWindowFlags(IDLE_WINDOW_FLAGS);
resetNotification(); resetNotification();
updateNotification(R.drawable.ic_play_arrow_white); updateNotification(R.drawable.ic_play_arrow_white);
videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white); videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white);
lockManager.releaseWifiAndCpu(); lockManager.releaseWifiAndCpu();
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
stopForeground(false); stopForeground(false);
} }
@ -732,15 +744,15 @@ public final class PopupVideoPlayer extends Service {
@Override @Override
public void onCompleted() { public void onCompleted() {
super.onCompleted(); super.onCompleted();
updateWindowFlags(IDLE_WINDOW_FLAGS);
resetNotification(); resetNotification();
updateNotification(R.drawable.ic_replay_white); updateNotification(R.drawable.ic_replay_white);
videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white); videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white);
lockManager.releaseWifiAndCpu(); lockManager.releaseWifiAndCpu();
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
stopForeground(false); stopForeground(false);
} }