Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BBDD89FAB for ; Mon, 12 Mar 2012 22:57:51 +0000 (UTC) Received: (qmail 24302 invoked by uid 500); 12 Mar 2012 22:57:51 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 24279 invoked by uid 500); 12 Mar 2012 22:57:51 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 24272 invoked by uid 99); 12 Mar 2012 22:57:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Mar 2012 22:57:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 50E746A3A; Mon, 12 Mar 2012 22:57:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: shazron@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/3] ios commit: Fixed CB-148, CB-316: Playing HTTP / HTTPS urls using the Media API is not working Message-Id: <20120312225751.50E746A3A@tyr.zones.apache.org> Date: Mon, 12 Mar 2012 22:57:51 +0000 (UTC) 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 Authored: Mon Mar 12 15:56:49 2012 -0700 Committer: Shazron Abdullah 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]; } }