Cordoba 3.3 Pausing and Resuming Recording Using the Media API

I am making a simple recorder for iOS 5.0+ using the Cordova Media API. I give the user the ability to start-pause-resume-stop audio recording.

The three buttons that I defined

Start recording

Stop recording

Pause / resume recording

I can successfully start and stop recording. What I cannot do is pause the recording and then resume it again.

I referenced the “API Examples” in Cordoba and used several as in my code.

Please help !!!

+4
source share
1

Media API, Media API.

- :

API PLUGIN

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 API PLUGIN

Media.js www org.apache.cordova.media.

, Media.prototype.startRecord.

/**
 * 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]);
};

, nameOfRecorder.pauseRecord(); nameOfRecorder.resumeRecord(); .

PS: Cordova 3.3 XCode 5.0.2

, .

+9

Source: https://habr.com/ru/post/1523891/


All Articles