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 2013/09/17 02:22:38 UTC
git commit: Revert "[CB-4847] iOS 7 microphone access requires user
permission - if denied, CDVCapture, CDVSound does not handle it properly"
Updated Branches:
refs/heads/master 0259d7666 -> 29d8c3812
Revert "[CB-4847] iOS 7 microphone access requires user permission - if denied, CDVCapture, CDVSound does not handle it properly"
This reverts commit 0259d766615724531a961058b591bc5903fc6c68.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/29d8c381
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/29d8c381
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/29d8c381
Branch: refs/heads/master
Commit: 29d8c381255c92d2b8b8d70e292b018ff0e3c3f5
Parents: 0259d76
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Sep 16 17:22:25 2013 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Sep 16 17:22:25 2013 -0700
----------------------------------------------------------------------
src/ios/CDVSound.m | 117 +++++++++++++++++++-----------------------------
1 file changed, 45 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/29d8c381/src/ios/CDVSound.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m
index 17ead13..5e9fd25 100644
--- a/src/ios/CDVSound.m
+++ b/src/ios/CDVSound.m
@@ -527,91 +527,64 @@
NSString* mediaId = [command.arguments objectAtIndex:0];
CDVAudioFile* audioFile = [self audioFileForResource:[command.arguments objectAtIndex:1] withId:mediaId doValidation:YES forRecording:YES];
- __block NSString* jsString = nil;
- __block NSString* errorMsg = @"";
+ NSString* jsString = nil;
+ NSString* errorMsg = @"";
if ((audioFile != nil) && (audioFile.resourceURL != nil)) {
- void (^startRecording)(void) = ^{
- NSError* __autoreleasing error = nil;
-
- if (audioFile.recorder != nil) {
- [audioFile.recorder stop];
- audioFile.recorder = nil;
- }
- // get the audioSession and set the category to allow recording when device is locked or ring/silent switch engaged
- if ([self hasAudioSession]) {
- [self.avSession setCategory:AVAudioSessionCategoryRecord error:nil];
- if (![self.avSession setActive:YES error:&error]) {
- // other audio with higher priority that does not allow mixing could cause this to fail
- errorMsg = [NSString stringWithFormat:@"Unable to record audio: %@", [error localizedFailureReason]];
- // jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
- jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]];
- [self.commandDelegate evalJs:jsString];
- return;
- }
- }
-
- // create a new recorder for each start record
- audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:nil error:&error];
-
- 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('org.apache.cordova.core.AudioHandler.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];
- }
+ NSError* __autoreleasing error = nil;
+
+ if (audioFile.recorder != nil) {
+ [audioFile.recorder stop];
+ audioFile.recorder = nil;
+ }
+ // get the audioSession and set the category to allow recording when device is locked or ring/silent switch engaged
+ if ([self hasAudioSession]) {
+ [self.avSession setCategory:AVAudioSessionCategoryRecord error:nil];
+ if (![self.avSession setActive:YES error:&error]) {
+ // other audio with higher priority that does not allow mixing could cause this to fail
+ errorMsg = [NSString stringWithFormat:@"Unable to record audio: %@", [error localizedFailureReason]];
+ // jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]];
- }
- if (jsString) {
[self.commandDelegate evalJs:jsString];
+ return;
+ }
+ }
+
+ // create a new recorder for each start record
+ audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:nil error:&error];
+
+ 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('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_STATE, MEDIA_RUNNING];
}
- };
-
- SEL rrpSel = NSSelectorFromString(@"requestRecordPermission:");
- if ([self hasAudioSession] && [self.avSession respondsToSelector:rrpSel])
- {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
- [self.avSession performSelector:rrpSel withObject:^(BOOL granted){
- if (granted) {
- startRecording();
- } else {
- NSString* msg = @"Error creating audio session, microphone permission denied.";
- NSLog(@"%@", msg);
- audioFile.recorder = nil;
- if (self.avSession) {
- [self.avSession setActive:NO error:nil];
- }
- jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:msg]];
- [self.commandDelegate evalJs:jsString];
- }
- }];
-#pragma clang diagnostic pop
- } else {
- startRecording();
}
+ 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,%@);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]];
+ }
} else {
// file did not validate
NSString* errorMsg = [NSString stringWithFormat:@"Could not record audio at '%@'", audioFile.resourcePath];
jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]];
+ }
+ if (jsString) {
[self.commandDelegate evalJs:jsString];
}
+ return;
}
- (void)stopRecordingAudio:(CDVInvokedUrlCommand*)command