ios - 如何在Parse上存储iOS录音?

标签 ios audio parse-platform recording

这里的新手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/

相关文章:

c++ - 在显示二进制数据时如何停止我的 Windows 控制台应用程序触发蜂鸣声

ios - MPMediaQuery 仅返回本地项目

ios - 如何在 swift 3 中使用 Backendless REST API

android - Android:MediaPlayer-免提音量

php - HTML5音频是静态文件时在iOS中显示 “live broadcast”

ios - Swift + Parse - 如何强制应用程序在注销后刷新

ios - 即使安装框架后也没有这样的模块 'Parse' 错误

ios - ParseFacebookUtilsV4 体系结构 armv7 的重复符号

ios - 监控 2 个或更多区域时出现 iBeacons 问题

ios - 构建 xcode 项目时界面生成器 Storyboard 编译器错误