Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhoneGap 3.x #4

Closed
bjudson opened this issue Jul 13, 2014 · 6 comments
Closed

PhoneGap 3.x #4

bjudson opened this issue Jul 13, 2014 · 6 comments

Comments

@bjudson
Copy link

bjudson commented Jul 13, 2014

Has anyone updated this plugin for PhoneGap 3.x? I understand it has a new plugin architecture. This plugin has been a lifesaver, and I'm still using it on PhoneGap 2.9, but thinking about upgrading.

@keenan
Copy link
Owner

keenan commented Jul 13, 2014

I moved away from this plugin to a simpler solution. I don't need to record in WAV and then compress. Doing it in two steps was a hack. That two step process, for me, caused the UI to hang for ~250ms during the compress step which made running animations jump. For my application it is better to just record directly into a minimal format. Here is how I did that:

note: This is the mod I made in Cordova 2.X but I imagine you could figure out how to patch this into 3.X easily

Step 1: add this to the startRecordingAudio method on SDVSound.m before audioFile.recorder =

    NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                    [NSNumber numberWithFloat:16000.0], AVSampleRateKey,
                                    [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                    nil];

Then I replaced:

audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:nil error:&error]; // Default PCM recording

With:

audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:recordSettings error:&error];

This records directly in M4A, mono in a relatively low fi (16K) format. For my application, which is just capturing words, not music this is just what I needed.

Note: when you make this change I got an error until I changed the contained file to a M4A ( eg. it erred when trying to use these setting to record into a file named xxx.wav).

@bjudson
Copy link
Author

bjudson commented Jul 13, 2014

Wow, that is so much better. I wonder why Cordova doesn't allow passing these settings in? Anyway, I will give it a shot; seems simple enough.

@bjudson bjudson closed this as completed Jul 13, 2014
@bjudson
Copy link
Author

bjudson commented Jul 14, 2014

I just wanted to follow up with one more change you left out, in case anyone else comes across this. CDVSound.m checks to make sure you're using a wav file. Simply changing this at the top of the file should prevent that:
#define RECORDING_WAV @"wav"

I changed it to:
#define RECORDING_WAV @"m4a"

Thanks again for pointing out this approach.

@kjakub
Copy link

kjakub commented Sep 25, 2014

@keenan ,@bjudson

Can you guys help me where i suppose to find SDVSound.m file and integrate it to plugin?

jhiswin added a commit to jhiswin/cordova-plugin-media-capture that referenced this issue Nov 27, 2014
record to m4a 16K mono to minimize file size
based on keenan/cordova-phonegap-audio-encode#4
@1nsaneinc
Copy link

where do we find this SDVSound.m file please?

@1nsaneinc
Copy link

OK nevermind! got it.
cordova-plugin-media/src/ios/CDVSound.m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants