mad*_*esh 4 audio-recording ios phonegap-plugins cordova cordova-3
我正在使用Cordova的Media API为iOS 5.0+制作一个简单的录音机.我正在为用户提供启动 - 暂停 - 恢复 - 停止录制音频的能力.
我定义的三个按钮是
开始录制
停止录制
暂停/恢复录制
我能够成功开始和停止录音.我无法做的是暂停录制然后再次恢复.
我提到了Cordova 的Media API示例,并且在我的代码中使用了一些.
请帮助!!!
通过扩展Media API插件,我能够使用Media API调用暂停和恢复记录功能.
以下是相同的解决方案:
媒体API插件的本质部分
将以下方法添加到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];
}
}
Run Code Online (Sandbox Code Playgroud)
JAVASCRIPT MEDIA API PLUGIN的一部分
将以下代码添加到org.apache.cordova.media的www文件夹下的Media.js文件中.
确保在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]);
};
Run Code Online (Sandbox Code Playgroud)
扩展插件后,只需调用nameOfRecorder .pauseRecord(); 和nameOfRecorder .resumeRecord(); 根据您的需求和要求.
PS:我正在使用Cordova 3.3和XCode 5.0.2
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
1826 次 |
| 最近记录: |