macdonst closed pull request #162: Fix CDVSound killing all audio when a single 
file finishes (retry on CB-7684)
URL: https://github.com/apache/cordova-plugin-media/pull/162
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m
index e1542871..ba4babab 100644
--- a/src/ios/CDVSound.m
+++ b/src/ios/CDVSound.m
@@ -187,7 +187,7 @@ - 
(CDVAudioFile*)audioFileForResource:(NSString*)resourcePath withId:(NSString*)
     return [self audioFileForResource:resourcePath withId:mediaId 
doValidation:bValidate forRecording:bRecord suppressValidationErrors:NO];
 }
 
-// returns whether or not audioSession is available - creates it if necessary
+// returns whether or not audioSession is available - retrieve the instance 
(app singleton) if necessary
 - (BOOL)hasAudioSession
 {
     BOOL bSession = YES;
@@ -198,7 +198,7 @@ - (BOOL)hasAudioSession
         self.avSession = [AVAudioSession sharedInstance];
         if (error) {
             // is not fatal if can't get AVAudioSession , just log the error
-            NSLog(@"error creating audio session: %@", [[error userInfo] 
description]);
+            NSLog(@"error retrieving audio session: %@", [[error userInfo] 
description]);
             self.avSession = nil;
             bSession = NO;
         }
@@ -469,9 +469,7 @@ - (BOOL)prepareToPlay:(CDVAudioFile*)audioFile 
withId:(NSString*)mediaId
     if (playerError != nil) {
         NSLog(@"Failed to initialize AVAudioPlayer: %@\n", [playerError 
localizedDescription]);
         audioFile.player = nil;
-        if (self.avSession) {
-            [self.avSession setActive:NO error:nil];
-        }
+
         bError = YES;
     } else {
         audioFile.player.mediaId = mediaId;
@@ -601,7 +599,6 @@ - (void)release:(CDVInvokedUrlCommand*)command
                 avPlayer = nil;
             }
             if (self.avSession) {
-                [self.avSession setActive:NO error:nil];
                 self.avSession = nil;
             }
             [[self soundCache] removeObjectForKey:mediaId];
@@ -705,9 +702,6 @@ - (void)startRecordingAudio:(CDVInvokedUrlCommand*)command
                     errorMsg = @"Failed to start recording using 
AVAudioRecorder";
                 }
                 audioFile.recorder = nil;
-                if (weakSelf.avSession) {
-                    [weakSelf.avSession setActive:NO error:nil];
-                }
                 [weakSelf onStatus:MEDIA_ERROR mediaId:mediaId param:
                            [self createAbortError:errorMsg]];
             }
@@ -725,9 +719,6 @@ - (void)startRecordingAudio:(CDVInvokedUrlCommand*)command
                     NSString* msg = @"Error creating audio session, microphone 
permission denied.";
                     NSLog(@"%@", msg);
                     audioFile.recorder = nil;
-                    if (weakSelf.avSession) {
-                        [weakSelf.avSession setActive:NO error:nil];
-                    }
                     [weakSelf onStatus:MEDIA_ERROR mediaId:mediaId param:
                            [self createAbortError:msg]];
                 }
@@ -773,9 +764,6 @@ - 
(void)audioRecorderDidFinishRecording:(AVAudioRecorder*)recorder successfully:
         [self onStatus:MEDIA_ERROR mediaId:mediaId param:
           [self createMediaErrorWithCode:MEDIA_ERR_DECODE message:nil]];
     }
-    if (self.avSession) {
-        [self.avSession setActive:NO error:nil];
-    }
 }
 
 - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer*)player 
successfully:(BOOL)flag
@@ -795,18 +783,12 @@ - 
(void)audioPlayerDidFinishPlaying:(AVAudioPlayer*)player successfully:(BOOL)fl
         [self onStatus:MEDIA_ERROR mediaId:mediaId param:
             [self createMediaErrorWithCode:MEDIA_ERR_DECODE message:nil]];
     }
-    if (self.avSession) {
-        [self.avSession setActive:NO error:nil];
-    }
 }
 
 -(void)itemDidFinishPlaying:(NSNotification *) notification {
     // Will be called when AVPlayer finishes playing playerItem
     NSString* mediaId = self.currMediaId;
 
-    if (self.avSession) {
-        [self.avSession setActive:NO error:nil];
-    }
     [self onStatus:MEDIA_STATE mediaId:mediaId param:@(MEDIA_STOPPED)];
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to