I was able to invoke the pause and resume functionalities of recorder using Media API by extending the Media API plugin.
Following is the solution of the same:
NATIVE PART OF MEDIA API PLUGIN
Add the following methods to CDVSound.m
CDVSound.m
- (void)resumeRecordingAudio:(CDVInvokedUrlCommand*)command
{
NSString* mediaId = [command.arguments objectAtIndex:0];
CDVAudioFile* audioFile = [[self soundCache] objectForKey:mediaId];
NSString* jsString = nil;
if ((audioFile != nil) && (audioFile.recorder != nil)) {
NSLog(@"Resumed recording audio sample '%@'", audioFile.resourcePath);
[audioFile.recorder record];
// no callback - that will happen in audioRecorderDidFinishRecording
}
// ignore if no media recording
if (jsString) {
[self.commandDelegate evalJs:jsString];
}
}
- (void)pauseRecordingAudio:(CDVInvokedUrlCommand*)command
{
NSString* mediaId = [command.arguments objectAtIndex:0];
CDVAudioFile* audioFile = [[self soundCache] objectForKey:mediaId];
NSString* jsString = nil;
if ((audioFile != nil) && (audioFile.recorder != nil)) {
NSLog(@"Paused recording audio sample '%@'", audioFile.resourcePath);
[audioFile.recorder pause];
// no callback - that will happen in audioRecorderDidFinishRecording
}
// ignore if no media recording
if (jsString) {
[self.commandDelegate evalJs:jsString];
}
}
JAVASCRIPT PART OF MEDIA API PLUGIN
Add the following code to the Media.js file under www folder of org.apache.cordova.media.
make sure you add the code below the Media.prototype.startRecord function.
/**
* Pause recording audio file.
*/
Media.prototype.pauseRecord = function() {
exec(null, this.errorCallback, "Media", "pauseRecordingAudio", [this.id]);
};
/**
* Resume recording audio file.
*/
Media.prototype.resumeRecord = function() {
exec(null, this.errorCallback, "Media", "resumeRecordingAudio", [this.id]);
};
Once you have extended the plugin, you simply have to call nameOfRecorder.pauseRecord(); and nameOfRecorder.resumeRecord(); as per your needs and requirements.
PS: I am using Cordova 3.3 with XCode 5.0.2
Hope this helps.
pauseRecord()
method...you would probably have to write this yourself either as an additional plugin or hack on the original plugin. You could also possibly use the Capture API to bring up the devices' native audio recording app which would probably have a pauseRecord function: github.com/apache/cordova-plugin-media-capture/blob/master/doc/…