diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/voice/VoiceNotePlaybackService.java b/app/src/main/java/org/thoughtcrime/securesms/components/voice/VoiceNotePlaybackService.java index a628098137..8ed7ba2dec 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/voice/VoiceNotePlaybackService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/voice/VoiceNotePlaybackService.java @@ -34,6 +34,7 @@ import com.google.common.util.concurrent.ListenableFuture; import org.signal.core.util.concurrent.SignalExecutors; import org.signal.core.util.logging.Log; +import org.thoughtcrime.securesms.attachments.AttachmentId; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.database.DatabaseObserver; import org.thoughtcrime.securesms.database.MessageTable; @@ -207,19 +208,31 @@ public class VoiceNotePlaybackService extends MediaSessionService { Log.d(TAG, "Current item is null or playback properties are null."); return; } - final Uri currentUi = currentItem.playbackProperties.uri; - final DatabaseAttachment attachment = SignalDatabase.attachments().getAttachment(new PartUriParser(currentUi).getPartId()); - if (attachment == null) { - player.stop(); - int playingIndex = player.getCurrentMediaItemIndex(); - player.removeMediaItem(playingIndex); - Log.d(TAG, "Currently playing item removed."); - } else { - Log.d(TAG, "Attachment was not null, therefore not deleted, therefore no action taken."); + + final Uri currentlyPlayingUri = currentItem.playbackProperties.uri; + + if (currentlyPlayingUri == VoiceNoteMediaItemFactory.NEXT_URI || currentlyPlayingUri == VoiceNoteMediaItemFactory.END_URI) { + Log.v(TAG, "Attachment deleted while voice note service was playing a system tone."); + } + + try { + final AttachmentId partId = new PartUriParser(currentlyPlayingUri).getPartId(); + final DatabaseAttachment attachment = SignalDatabase.attachments().getAttachment(partId); + if (attachment == null) { + player.stop(); + int playingIndex = player.getCurrentMediaItemIndex(); + player.removeMediaItem(playingIndex); + Log.d(TAG, "Currently playing item removed."); + } else { + Log.d(TAG, "Attachment was not null, therefore not deleted, therefore no action taken."); + } + } catch (NumberFormatException ex) { + Log.w(TAG, "Could not parse currently playing URI into an attachmentId.", ex); } } }); } + /** * Some devices, such as the ASUS Zenfone 8, erroneously report multiple broadcast receivers for {@value Intent#ACTION_MEDIA_BUTTON} in the package manager. * This triggers a failure within the {@link MediaSession} initialization and throws an {@link IllegalStateException}.