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) {
Log.d(TAG, "N_ recreatePopupPlayerNotification(true)"); if (DEBUG) {
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) {
Log.d(TAG, "N_ recreatePopupPlayerNotification()"); if (DEBUG) {
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) {
Log.d(TAG, "N_ recreateBackgroundPlayerNotification(true)"); if (DEBUG) {
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) {
Log.d(TAG, "N_ recreateBackgroundPlayerNotification()"); if (DEBUG) {
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,33 +74,35 @@ public class MediaSessionManager {
return; return;
} }
if (getMetadataAlbumArt() == null) { if (DEBUG) {
Log.d(TAG, "N_getMetadataAlbumArt: thumb == null"); if (getMetadataAlbumArt() == null) {
} Log.d(TAG, "N_getMetadataAlbumArt: thumb == null");
if (getMetadataTitle() == null) { }
Log.d(TAG, "N_getMetadataTitle: title == null"); if (getMetadataTitle() == null) {
} Log.d(TAG, "N_getMetadataTitle: title == null");
if (getMetadataArtist() == null) { }
Log.d(TAG, "N_getMetadataArtist: artist == null"); if (getMetadataArtist() == null) {
} Log.d(TAG, "N_getMetadataArtist: artist == null");
if (getMetadataDuration() <= 1) { }
Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration()); if (getMetadataDuration() <= 1) {
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) {
Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist if (DEBUG) {
+ " thumb: " + albumArt.hashCode() + " d: " + duration); Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist
mediaSession.setMetadata( + " thumb: " + albumArt.hashCode() + " d: " + duration);
new MediaMetadataCompat.Builder() }
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, albumArt) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt)
.build() .putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, albumArt)
); .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration).build());
tmpThumbHash = albumArt.hashCode(); tmpThumbHash = albumArt.hashCode();
} }
} }