这里的新手iOS编码器,如果答案真的很简单,则表示歉意。
所以我在viewDidLoad中设置了录音
// Set the audio file
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
我有一个酒吧按钮,它记录新的音频文件:
// Stop the audio player before recording
if (player.playing) {
[player stop];
}
if (!recorder.recording) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
// Start recording
[recorder record];
} else {
// Pause recording
[recorder pause];
}
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStylePlain target:self
action:@selector(stopTapped)];
然后开始变成停止按钮
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStylePlain target:self
action:@selector(actionNew)];
如何将其添加为PFFile并保存在Parse的词典中?
我已经阅读了很多Parse文档,但仍然没有真正掌握它。任何帮助,不胜感激。
最佳答案
看起来最简单的解决方案是在用户完成录制后从手机加载文件,而不是尝试将录制直接保存到NSData
对象。如果要直接记录到NSData
对象,请查看apple docs和此stackoverflow question。
首先,您要在用户完成录制后获取NSData
的实例:
NSData *audioData = [[NSData alloc] initWithContentsOfFile:filePath];
新建一个PFFile:
PFFile *file = [PFFile fileWithName:@"resume.txt" data:data];
然后使用所需的保存方法进行保存。
关于ios - 如何在Parse上存储iOS录音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28572828/