You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/11/28 00:58:42 UTC

ios commit: [CB-1669] Issue an error when media.startRecord() is failing.

Updated Branches:
  refs/heads/master 5013589f2 -> cf5609fd2


[CB-1669] Issue an error when media.startRecord() is failing.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/cf5609fd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/cf5609fd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/cf5609fd

Branch: refs/heads/master
Commit: cf5609fd29d083c5833416225c78a72f9833ca82
Parents: 5013589
Author: cpojer <ch...@gmail.com>
Authored: Thu Oct 18 03:27:47 2012 +0200
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue Nov 27 15:58:29 2012 -0800

----------------------------------------------------------------------
 CordovaLib/Classes/CDVSound.m |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/cf5609fd/CordovaLib/Classes/CDVSound.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVSound.m b/CordovaLib/Classes/CDVSound.m
index 85e8b30..81cde78 100644
--- a/CordovaLib/Classes/CDVSound.m
+++ b/CordovaLib/Classes/CDVSound.m
@@ -438,20 +438,28 @@
         // create a new recorder for each start record
         audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:nil error:&error];
 
-        if (error != nil) {
-            errorMsg = [NSString stringWithFormat:@"Failed to initialize AVAudioRecorder: %@\n", [error  localizedFailureReason]];
+        bool recordingSuccess = NO;
+        if (error == nil) {
+            audioFile.recorder.delegate = self;
+            audioFile.recorder.mediaId = mediaId;
+            recordingSuccess = [audioFile.recorder record];
+            if (recordingSuccess) {
+                NSLog(@"Started recording audio sample '%@'", audioFile.resourcePath);
+                jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_STATE, MEDIA_RUNNING];
+            }
+        }
+
+        if (error != nil || recordingSuccess == NO) {
+            if (error != nil) {
+                errorMsg = [NSString stringWithFormat:@"Failed to initialize AVAudioRecorder: %@\n", [error localizedFailureReason]];
+            } else {
+                errorMsg = @"Failed to start recording using AVAudioRecorder";
+            }
             audioFile.recorder = nil;
             if (self.avSession) {
                 [self.avSession setActive:NO error:nil];
             }
-            // jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
             jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]];
-        } else {
-            audioFile.recorder.delegate = self;
-            audioFile.recorder.mediaId = mediaId;
-            [audioFile.recorder record];
-            NSLog(@"Started recording audio sample '%@'", audioFile.resourcePath);
-            jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_STATE, MEDIA_RUNNING];
         }
     } else {
         // file does not exist