Log only in debug build

This commit is contained in:
wb9688 2020-05-15 15:05:20 +02:00
parent 7d499ffba1
commit caf7c55069
2 changed files with 38 additions and 26 deletions

View file

@ -75,7 +75,9 @@ public final class NotificationUtil {
if (areOldNotificationsEnabled) { if (areOldNotificationsEnabled) {
notificationBuilder = createOldPopupPlayerNotification(context, playerImpl); notificationBuilder = createOldPopupPlayerNotification(context, playerImpl);
} else if (notificationBuilder == null || recreate) { } else if (notificationBuilder == null || recreate) {
if (DEBUG) {
Log.d(TAG, "N_ recreatePopupPlayerNotification(true)"); Log.d(TAG, "N_ recreatePopupPlayerNotification(true)");
}
notificationBuilder = createPopupPlayerNotification(context, mediaSessionCompatToken, notificationBuilder = createPopupPlayerNotification(context, mediaSessionCompatToken,
playerImpl, sharedPreferences); playerImpl, sharedPreferences);
} }
@ -91,7 +93,9 @@ public final class NotificationUtil {
if (areOldNotificationsEnabled) { if (areOldNotificationsEnabled) {
notificationBuilder = createOldPopupPlayerNotification(context, playerImpl); notificationBuilder = createOldPopupPlayerNotification(context, playerImpl);
} else if (notificationBuilder == null) { } else if (notificationBuilder == null) {
if (DEBUG) {
Log.d(TAG, "N_ recreatePopupPlayerNotification()"); Log.d(TAG, "N_ recreatePopupPlayerNotification()");
}
notificationBuilder = createPopupPlayerNotification(context, notificationBuilder = createPopupPlayerNotification(context,
mediaSessionCompatToken, playerImpl, sharedPreferences); mediaSessionCompatToken, playerImpl, sharedPreferences);
} }
@ -105,7 +109,9 @@ public final class NotificationUtil {
final boolean areOldNotificationsEnabled = sharedPreferences final boolean areOldNotificationsEnabled = sharedPreferences
.getBoolean(context.getString(R.string.enable_old_notifications_key), false); .getBoolean(context.getString(R.string.enable_old_notifications_key), false);
if (notificationBuilder == null || recreate || areOldNotificationsEnabled) { if (notificationBuilder == null || recreate || areOldNotificationsEnabled) {
if (DEBUG) {
Log.d(TAG, "N_ recreateBackgroundPlayerNotification(true)"); Log.d(TAG, "N_ recreateBackgroundPlayerNotification(true)");
}
notificationBuilder = createBackgroundPlayerNotification(context, notificationBuilder = createBackgroundPlayerNotification(context,
mediaSessionCompatToken, basePlayerImpl, sharedPreferences); mediaSessionCompatToken, basePlayerImpl, sharedPreferences);
} }
@ -119,7 +125,9 @@ public final class NotificationUtil {
final boolean areOldNotificationsEnabled = sharedPreferences final boolean areOldNotificationsEnabled = sharedPreferences
.getBoolean(context.getString(R.string.enable_old_notifications_key), false); .getBoolean(context.getString(R.string.enable_old_notifications_key), false);
if (notificationBuilder == null || areOldNotificationsEnabled) { if (notificationBuilder == null || areOldNotificationsEnabled) {
if (DEBUG) {
Log.d(TAG, "N_ recreateBackgroundPlayerNotification()"); Log.d(TAG, "N_ recreateBackgroundPlayerNotification()");
}
notificationBuilder = createBackgroundPlayerNotification(context, notificationBuilder = createBackgroundPlayerNotification(context,
mediaSessionCompatToken, basePlayerImpl, sharedPreferences); mediaSessionCompatToken, basePlayerImpl, sharedPreferences);
} }

View file

@ -16,12 +16,14 @@ import androidx.media.session.MediaButtonReceiver;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.player.mediasession.MediaSessionCallback; import org.schabi.newpipe.player.mediasession.MediaSessionCallback;
import org.schabi.newpipe.player.mediasession.PlayQueueNavigator; import org.schabi.newpipe.player.mediasession.PlayQueueNavigator;
import org.schabi.newpipe.player.mediasession.PlayQueuePlaybackController; import org.schabi.newpipe.player.mediasession.PlayQueuePlaybackController;
public class MediaSessionManager { public class MediaSessionManager {
private static final String TAG = "MediaSessionManager"; private static final String TAG = "MediaSessionManager";
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
@NonNull @NonNull
private final MediaSessionCompat mediaSession; private final MediaSessionCompat mediaSession;
@ -72,6 +74,7 @@ public class MediaSessionManager {
return; return;
} }
if (DEBUG) {
if (getMetadataAlbumArt() == null) { if (getMetadataAlbumArt() == null) {
Log.d(TAG, "N_getMetadataAlbumArt: thumb == null"); Log.d(TAG, "N_getMetadataAlbumArt: thumb == null");
} }
@ -84,21 +87,22 @@ public class MediaSessionManager {
if (getMetadataDuration() <= 1) { if (getMetadataDuration() <= 1) {
Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration()); Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration());
} }
}
if (getMetadataAlbumArt() == null || getMetadataTitle() == null if (getMetadataAlbumArt() == null || getMetadataTitle() == null
|| getMetadataArtist() == null || getMetadataDuration() <= 1 || getMetadataArtist() == null || getMetadataDuration() <= 1
|| albumArt.hashCode() != tmpThumbHash) { || albumArt.hashCode() != tmpThumbHash) {
if (DEBUG) {
Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist
+ " thumb: " + albumArt.hashCode() + " d: " + duration); + " thumb: " + albumArt.hashCode() + " d: " + duration);
mediaSession.setMetadata( }
new MediaMetadataCompat.Builder()
mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt)
.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, albumArt) .putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, albumArt)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration).build());
.build()
);
tmpThumbHash = albumArt.hashCode(); tmpThumbHash = albumArt.hashCode();
} }
} }