Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Linking to externally hosted plugin

  • Loading branch information...
commit f5b3536eb56828308bcf225b29b757a312d306eb 1 parent 0762a4b
keenan keenan authored
20 iOS/AudioEncode/AudioEncode.h
View
@@ -1,20 +0,0 @@
-//
-// AudioEncode.h
-//
-// By Lyle Pratt, September 2011.
-// Updated Oct 2012 by Keenan Wyrobek for Cordova 2.1.0
-// MIT licensed
-//
-
-#import <Foundation/Foundation.h>
-#import <AVFoundation/AVFoundation.h>
-#import <Cordova/CDV.h>
-
-@interface AudioEncode : CDVPlugin{
- NSString* callbackId;
-}
-
-@property (nonatomic, retain) NSString* callbackId;
-
-- (void)encodeAudio:(NSArray*)arguments withDict:(NSDictionary*)options;
-@end
26 iOS/AudioEncode/AudioEncode.js
View
@@ -1,26 +0,0 @@
-//
-// AudioEncode.js
-//
-// Created by Lyle Pratt, September 2011.
-// Updated Opt 2012 by Keenan Wyrobek for Cordova 2.1.0
-// MIT licensed
-//
-
-/**
- * This class converts audio at a file path to M4A format
- * @constructor
- */
-
-function CompressAudio(originalSrc, externalSuccessCallback, failCallback, passThroughObject){
-
- cordova.exec(successCallback,
- failCallback,
- "AudioEncode",
- "encodeAudio",
- [originalSrc]);
-
- function successCallback(newSource){
- if (passThroughObject) return externalSuccessCallback(newSource, passThroughObject);
- else return externalSuccessCallback(newSource);
- }
-}
79 iOS/AudioEncode/AudioEncode.m
View
@@ -1,79 +0,0 @@
-//
-// AudioEncode.m
-//
-// By Lyle Pratt, September 2011.
-// Updated Oct 2012 by Keenan Wyrobek for Cordova 2.1.0
-// MIT licensed
-//
-
-#import "AudioEncode.h"
-
-@implementation AudioEncode
-
-@synthesize callbackId;
-
-- (void)encodeAudio:(NSArray*)arguments withDict:(NSDictionary*)options
-{
- self.callbackId = [arguments objectAtIndex:0];
- NSString* audioPath = [arguments objectAtIndex:1];
-
- NSURL* audioURL = [NSURL fileURLWithPath:audioPath];
- AVURLAsset* audioAsset = [[AVURLAsset alloc] initWithURL:audioURL options:nil];
- AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset:audioAsset presetName:AVAssetExportPresetAppleM4A];
-
- NSURL* exportURL = [NSURL fileURLWithPath:[[audioPath componentsSeparatedByString:@".wav"] objectAtIndex:0]];
- NSURL* destinationURL = [exportURL URLByAppendingPathExtension:@"m4a"];
-
- exportSession.outputURL = destinationURL;
- exportSession.outputFileType = AVFileTypeAppleM4A;
-
- [exportSession exportAsynchronouslyWithCompletionHandler:^{
-
- if (AVAssetExportSessionStatusCompleted == exportSession.status) {
- NSLog(@"AVAssetExportSessionStatusCompleted");
- [self performSelectorOnMainThread:@selector(doSuccessCallback:) withObject:[exportSession.outputURL path] waitUntilDone:NO];
- } else if (AVAssetExportSessionStatusFailed == exportSession.status) {
- // a failure may happen because of an event out of your control
- // for example, an interruption like a phone call comming in
- // make sure and handle this case appropriately
- NSLog(@"AVAssetExportSessionStatusFailed");
- [self performSelectorOnMainThread:@selector(doFailCallback:) withObject:[NSString stringWithFormat:@"%i", exportSession.status] waitUntilDone:NO];
-
- } else {
- NSLog(@"Export Session Status: %d", exportSession.status);
- }
-
- [exportSession release];
- }];
-
-
- NSFileManager *fileMgr = [NSFileManager defaultManager];
- NSError *error = noErr;
- if ([fileMgr removeItemAtPath:audioPath error:&error] != YES) {
- NSLog(@"Unable to delete file: %@", [error localizedDescription]);
- }
-}
-
--(void) doSuccessCallback:(NSString*)path {
- NSLog(@"doing success callback");
-
- CDVPluginResult* pluginResult = nil;
- NSString* javaScript = nil;
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:path];
- javaScript = [pluginResult toSuccessCallbackString:self.callbackId];
- [self writeJavascript:javaScript];
-}
-
--(void) doFailCallback:(NSString*)status {
- NSLog(@"doing fail callback");
-
- CDVPluginResult* pluginResult = nil;
- NSString* javaScript = nil;
-
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:status];
- javaScript = [pluginResult toErrorCallbackString:self.callbackId];
-
- [self writeJavascript:javaScript];
-}
-
-@end
52 iOS/AudioEncode/README.md
View
@@ -1,52 +1,6 @@
## PhoneGap AudioEncode Plugin ##
- * by Lyle Pratt
- * Updated Oct 2012 by Keenan Wyrobek for Cordova 2.1.0
-## About this Plugin ##
-
-This plugin lets you easily convert WAV audio into M4A audio. It is useful when using Phonegap's audio capture or media recording functionality. Uploading WAV files on via cellular connections is not advised. M4A encoded files are 1/4 to 1/10 the size.
-
-## Using the Plugin ##
-
-The plugin creates a global CompressAudio(originalSrc, success, fail, obj) method.
- * originalSrc: (required) This is a string path to the local file to encode. This is typically the fullPath property of the entry passed to the success of a fileSystem.root.getFile call
- * success: (required) This function is called when the encoding has completed successfully. It will be called in one of two ways.
- * if obj is passed into CompressAudio - success(m4ASource, obj)
- * if obj is not passed into CompressAudio - success(m4ASource)
- * fail: (required) This function is called on encode failure and will be passed a statusCode.
- * obj: (optional) this object is passed through to success function.
-
-Example:
-
- CompressAudio(pathToWavFile, success, fail);
-
- var success = function(newM4APath) {
- //Do something with your new encoded audio (upload it?)
- console.log(newM4APath);
- }
-
- var fail = function(statusCode) {
- //Why did it fail?
- console.log(statusCode);
- }
-
-## Adding the Plugin to your project ##
-
-Using this plugin requires [iPhone PhoneGap](http://github.com/phonegap/phonegap-iphone)
-
-1. This plug in has been tested with Cordova/PhoneGap 2.1.0
-2. Add the .h and .m files to your Plugins folder in your project.
-3. Add the .js files to your "www" folder on disk, and add reference(s) to the .js files in your html file(s).
-
-## LICENSE ##
-
-The MIT License
-
-Copyright (c) 2011 Lyle Pratt
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+This plugin lets you easily convert/compress/encode WAV audio into M4A audio. It is useful when using Phonegap's audio capture or media recording functionality. Uploading WAV files on via cellular connections is not advised. M4A encoded files are 1/4 to 1/10 the size.
+Project is hosted here.
+https://github.com/keenan/cordova-phonegap-audio-encode
Please sign in to comment.
Something went wrong with that request. Please try again.