【问题标题】:How store iOS audio recordings on Parse?如何在 Parse 上存储 iOS 录音?
【发布时间】:2015-02-17 23:00:12
【问题描述】:

这里是新手 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 文档,但仍然没有真正掌握它。非常感谢任何帮助。

【问题讨论】:

    标签: ios audio parse-platform recording


    【解决方案1】:

    看起来最简单的解决方案是在用户完成录制后从手机加载文件,而不是尝试将录制内容直接保存到 NSData 对象。如果您想直接查看NSData 对象的记录,请查看apple docs 和此stackoverflow question

    首先你想在用户完成录制后获取NSData 的实例:

    NSData *audioData = [[NSData alloc] initWithContentsOfFile:filePath];
    

    制作一个新的 PFFile :

    PFFile *file = [PFFile fileWithName:@"resume.txt" data:data];
    

    然后用你想要的保存方式保存。

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 2014-09-09
      • 2023-03-31
      相关资源
      最近更新 更多