incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject [1/3] ios commit: Fixed CB-148, CB-316: Playing HTTP / HTTPS urls using the Media API is not working
Date Mon, 12 Mar 2012 22:57:51 GMT
Updated Branches:
  refs/heads/master f47a9a083 -> 0984e4def


Fixed CB-148, CB-316: Playing HTTP / HTTPS urls using the Media API is not working


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

Branch: refs/heads/master
Commit: 0984e4def9065009d2db521d9aa442cbc5542791
Parents: 234319a
Author: Shazron Abdullah <shazron@apache.org>
Authored: Mon Mar 12 15:56:49 2012 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Mon Mar 12 15:56:49 2012 -0700

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


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0984e4de/CordovaLib/Classes/CDVSound.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVSound.m b/CordovaLib/Classes/CDVSound.m
index e615e56..d6d77d1 100644
--- a/CordovaLib/Classes/CDVSound.m
+++ b/CordovaLib/Classes/CDVSound.m
@@ -23,6 +23,7 @@
 
 #define DOCUMENTS_SCHEME_PREFIX		@"documents://"
 #define HTTP_SCHEME_PREFIX			@"http://"
+#define HTTPS_SCHEME_PREFIX			@"https://"
 
 @implementation CDVSound
 
@@ -37,7 +38,7 @@
 	
     // first try to find HTTP:// or Documents:// resources
     
-    if ([resourcePath hasPrefix:HTTP_SCHEME_PREFIX]){
+    if ([resourcePath hasPrefix:HTTP_SCHEME_PREFIX] || [resourcePath hasPrefix:HTTPS_SCHEME_PREFIX]){
         // if it is a http url, use it
         NSLog(@"Will use resource '%@' from the Internet.", resourcePath);
         resourceURL = [NSURL URLWithString:resourcePath];
@@ -223,11 +224,21 @@
     } else {
         NSURLRequest *request = [NSURLRequest requestWithURL:resourceURL];
         NSURLResponse *response = nil;
-        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response
error:&playerError];
+        NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response
error:&playerError];
         if (playerError) {
             NSLog(@"Unable to download audio from: %@", [resourceURL absoluteString]);
         } else {
-            audioFile.player = [[[ CDVAudioPlayer alloc ] initWithData:data error:&playerError]
autorelease];
+            
+            // bug in AVAudioPlayer when playing downloaded data in NSData - we have to download
the file and play from disk
+            CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
+            CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
+            NSString* filePath = [NSString stringWithFormat:@"%@/%@.mp3", NSTemporaryDirectory(),
uuidString];
+            CFRelease(uuidString);
+            CFRelease(uuidRef);
+            
+            [data writeToFile:filePath atomically:YES];            
+            NSURL* fileURL = [NSURL fileURLWithPath:filePath];
+            audioFile.player = [[[ CDVAudioPlayer alloc ] initWithContentsOfURL:fileURL error:&playerError]
autorelease];
         }
     }
     


Mime
View raw message