-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:
parent
e7d23176b7
commit
aa1878c15a
3 changed files with 46 additions and 25 deletions
|
@ -199,7 +199,6 @@ public final class BackgroundPlayer extends Service {
|
|||
|
||||
remoteViews.setTextViewText(R.id.notificationSongName, basePlayerImpl.getVideoTitle());
|
||||
remoteViews.setTextViewText(R.id.notificationArtist, basePlayerImpl.getUploaderName());
|
||||
remoteViews.setImageViewBitmap(R.id.notificationCover, basePlayerImpl.getThumbnail());
|
||||
|
||||
remoteViews.setOnClickPendingIntent(R.id.notificationPlayPause,
|
||||
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
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
private void updateNotificationThumbnail() {
|
||||
if (notRemoteView != null) {
|
||||
notRemoteView.setImageViewBitmap(R.id.notificationCover,
|
||||
basePlayerImpl.getThumbnail());
|
||||
}
|
||||
if (bigNotRemoteView != null) {
|
||||
bigNotRemoteView.setImageViewBitmap(R.id.notificationCover,
|
||||
basePlayerImpl.getThumbnail());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||
resetNotification();
|
||||
updateNotificationThumbnail();
|
||||
updateNotification(-1);
|
||||
}
|
||||
|
||||
|
@ -306,13 +317,7 @@ public final class BackgroundPlayer extends Service {
|
|||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
super.onLoadingFailed(imageUri, view, failReason);
|
||||
resetNotification();
|
||||
updateNotification(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
super.onLoadingCancelled(imageUri, view);
|
||||
resetNotification();
|
||||
updateNotificationThumbnail();
|
||||
updateNotification(-1);
|
||||
}
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -395,6 +400,7 @@ public final class BackgroundPlayer extends Service {
|
|||
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||
super.onMetadataChanged(tag);
|
||||
resetNotification();
|
||||
updateNotificationThumbnail();
|
||||
updateNotification(-1);
|
||||
updateMetadata();
|
||||
}
|
||||
|
@ -525,6 +531,7 @@ public final class BackgroundPlayer extends Service {
|
|||
public void onPlaying() {
|
||||
super.onPlaying();
|
||||
resetNotification();
|
||||
updateNotificationThumbnail();
|
||||
updateNotification(R.drawable.ic_pause_white);
|
||||
lockManager.acquireWifiAndCpu();
|
||||
}
|
||||
|
@ -533,6 +540,7 @@ public final class BackgroundPlayer extends Service {
|
|||
public void onPaused() {
|
||||
super.onPaused();
|
||||
resetNotification();
|
||||
updateNotificationThumbnail();
|
||||
updateNotification(R.drawable.ic_play_arrow_white);
|
||||
lockManager.releaseWifiAndCpu();
|
||||
}
|
||||
|
@ -547,6 +555,7 @@ public final class BackgroundPlayer extends Service {
|
|||
if (notRemoteView != null) {
|
||||
notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false);
|
||||
}
|
||||
updateNotificationThumbnail();
|
||||
updateNotification(R.drawable.ic_replay_white);
|
||||
lockManager.releaseWifiAndCpu();
|
||||
}
|
||||
|
|
|
@ -1044,17 +1044,17 @@ public abstract class BasePlayer implements
|
|||
|
||||
@NonNull
|
||||
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
|
||||
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
|
||||
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
|
||||
|
|
|
@ -98,6 +98,11 @@ public final class PopupVideoPlayer extends Service {
|
|||
|
||||
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.LayoutParams windowLayoutParams;
|
||||
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 ?
|
||||
WindowManager.LayoutParams.TYPE_PHONE :
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
final int interactiveInputMethodLayout = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
||||
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
|
||||
|
||||
windowLayoutParams = new WindowManager.LayoutParams(
|
||||
(int) popupWidth, (int) getMinimumVideoHeight(popupWidth),
|
||||
layoutParamType,
|
||||
interactiveInputMethodLayout,
|
||||
IDLE_WINDOW_FLAGS,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
|
||||
|
@ -249,11 +252,15 @@ public final class PopupVideoPlayer extends Service {
|
|||
|
||||
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)
|
||||
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.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 {
|
||||
|
@ -684,16 +697,15 @@ public final class PopupVideoPlayer extends Service {
|
|||
@Override
|
||||
public void onPlaying() {
|
||||
super.onPlaying();
|
||||
|
||||
updateWindowFlags(ONGOING_PLAYBACK_WINDOW_FLAGS);
|
||||
|
||||
resetNotification();
|
||||
updateNotification(R.drawable.ic_pause_white);
|
||||
|
||||
videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white);
|
||||
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());
|
||||
lockManager.acquireWifiAndCpu();
|
||||
}
|
||||
|
@ -708,15 +720,15 @@ public final class PopupVideoPlayer extends Service {
|
|||
@Override
|
||||
public void onPaused() {
|
||||
super.onPaused();
|
||||
|
||||
updateWindowFlags(IDLE_WINDOW_FLAGS);
|
||||
|
||||
resetNotification();
|
||||
updateNotification(R.drawable.ic_play_arrow_white);
|
||||
|
||||
videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white);
|
||||
lockManager.releaseWifiAndCpu();
|
||||
|
||||
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
|
||||
|
||||
stopForeground(false);
|
||||
}
|
||||
|
||||
|
@ -732,15 +744,15 @@ public final class PopupVideoPlayer extends Service {
|
|||
@Override
|
||||
public void onCompleted() {
|
||||
super.onCompleted();
|
||||
|
||||
updateWindowFlags(IDLE_WINDOW_FLAGS);
|
||||
|
||||
resetNotification();
|
||||
updateNotification(R.drawable.ic_replay_white);
|
||||
|
||||
videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white);
|
||||
lockManager.releaseWifiAndCpu();
|
||||
|
||||
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
|
||||
|
||||
stopForeground(false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue