From 3e8b4225b363fc8fdeced45a3fd83aef590f3583 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 12 May 2017 10:12:06 -0400 Subject: [PATCH] Show alert when user tries to play an invalid audio file. // FREEBIE --- .../Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m | 5 +++++ Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m | 9 +++++++++ Signal/translations/en.lproj/Localizable.strings | 3 +++ 3 files changed, 17 insertions(+) diff --git a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m index b45af2084..686f3c169 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m @@ -340,6 +340,11 @@ NS_ASSUME_NONNULL_BEGIN if (self.audioDurationSeconds == 0.f) { NSError *error; AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.fileURL error:&error]; + if (error && [error.domain isEqualToString:NSOSStatusErrorDomain] + && (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) { + // Ignore "invalid audio file" errors. + return; + } OWSAssert(!error); if (!error) { self.audioDurationSeconds = (CGFloat)[audioPlayer duration]; diff --git a/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m b/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m index afd67594d..740a950a7 100644 --- a/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m +++ b/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m @@ -3,6 +3,7 @@ // #import "OWSAudioAttachmentPlayer.h" +#import "Signal-Swift.h" #import "TSAttachment.h" #import "TSAttachmentStream.h" #import "TSVideoAttachmentAdapter.h" @@ -111,6 +112,14 @@ NS_ASSUME_NONNULL_BEGIN if (error) { DDLogError(@"%@ error: %@", self.tag, error); [self stop]; + + if ([error.domain isEqualToString:NSOSStatusErrorDomain] + && (error.code == kAudioFileInvalidFileError || error.code == kAudioFileStreamError_InvalidFile)) { + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"") + message:NSLocalizedString(@"INVALID_AUDIO_FILE_ALERT_ERROR_MESSAGE", + @"Message for the alert indicating that an audio file is invalid.")]; + } + return; } self.audioPlayer.delegate = self; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index c432ef8fe..4892bdda8 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -580,6 +580,9 @@ /* No comment provided by engineer. */ "INCOMING_INCOMPLETE_CALL" = "Incomplete incoming call from"; +/* Message for the alert indicating that an audio file is invalid. */ +"INVALID_AUDIO_FILE_ALERT_ERROR_MESSAGE" = "Invalid audio file."; + /* Alert body when contacts disabled while trying to invite contacts to signal */ "INVITE_FLOW_REQUIRES_CONTACT_ACCESS_BODY" = "To invite your contacts, you need to allow Signal access to your contacts in the Settings app.";