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 2014/01/16 01:23:54 UTC

git commit: [CB-4755] Fix crash in Media.setVolume on iOS

Updated Branches:
  refs/heads/dev 65890edf2 -> a8cd8f992


[CB-4755] Fix crash in Media.setVolume on iOS

Media.setVolume caused the application to crash after Media.release was
called. Code causing crash:

  var m = new Media("test.caf");
  m.release();
  m.setVolume(1); // crash in this call

The reason was that retrieving the CDVAudioFile instance from the sound
cache would return nil after Media.release. This patch fixes the issue
by explicitely checking for nil. It also does away with an unnecessary
cache initialization, which isn't needed as -[Media setVolume:] doesn't
write to the cache.

Signed-off-by: Michael Hanselmann <pu...@hansmi.ch>


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/a8cd8f99
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/a8cd8f99
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/a8cd8f99

Branch: refs/heads/dev
Commit: a8cd8f9925c82ebb90b9a75474d1259a79608963
Parents: 65890ed
Author: Michael Hanselmann <pu...@hansmi.ch>
Authored: Tue Jan 14 19:10:03 2014 +0100
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Jan 15 16:23:45 2014 -0800

----------------------------------------------------------------------
 src/ios/CDVSound.m | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/a8cd8f99/src/ios/CDVSound.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m
index 14b2fc2..187f370 100644
--- a/src/ios/CDVSound.m
+++ b/src/ios/CDVSound.m
@@ -267,16 +267,15 @@
     NSString* mediaId = [command.arguments objectAtIndex:0];
     NSNumber* volume = [command.arguments objectAtIndex:1 withDefault:[NSNumber numberWithFloat:1.0]];
 
-    CDVAudioFile* audioFile;
-    if ([self soundCache] == nil) {
-        [self setSoundCache:[NSMutableDictionary dictionaryWithCapacity:1]];
-    } else {
-        audioFile = [[self soundCache] objectForKey:mediaId];
-        audioFile.volume = volume;
-        if (audioFile.player) {
-            audioFile.player.volume = [volume floatValue];
+    if ([self soundCache] != nil) {
+        CDVAudioFile* audioFile = [[self soundCache] objectForKey:mediaId];
+        if (audioFile != nil) {
+            audioFile.volume = volume;
+            if (audioFile.player) {
+                audioFile.player.volume = [volume floatValue];
+            }
+            [[self soundCache] setObject:audioFile forKey:mediaId];
         }
-        [[self soundCache] setObject:audioFile forKey:mediaId];
     }
 
     // don't care for any callbacks