【问题标题】:adding saving and deleting function to audio recorder program for iphone为iphone的录音机程序添加保存和删除功能
【发布时间】:2013-09-04 17:22:57
【问题描述】:

所以我按照一些在线教程创建了一个适用于 iPhone 的录音机应用程序,它允许我录制和播放声音文件。

但我找不到任何教程可以让我将录音保存到表格视图中,然后选择要播放的文件。谁能指导我到哪里需要修改我的代码以添加保存和删除功能?

我的代码:

(void)viewDidLoad { [超级viewDidLoad];

// Disable Stop/Play button when application launches
[stopButton setEnabled:NO];
[playButton setEnabled:NO];

// 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];

}

【问题讨论】:

    标签: iphone ios audio


    【解决方案1】:

    我会使用各种NSFileManager 实用程序来控制保存和删除。 AVAudioRecorder 在调用 prepareToRecord 时会在磁盘上创建一个文件,因此您在录制后的选择是:

    1. 删除它 ([[NSFileManager defaultManager]removeItemAtPath:path error:&error];)
    2. 不要 == 保存

    对于 tableview ,您可以使用 NSArray *fileNames = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:theDirectoryPath error:&error]; 获取音频文件名。 (顺便说一句 - 我会创建 docs 目录的子目录,特别是用于音频,所以你知道你正在查看的目录中的所有内容都是音频文件。 - 还有一个 NSFileManager 方法。删除如上,大概在适当的委托/数据源方法中使用AVAudioPlayer 和来自NSFileManager 调用的路径

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 2015-07-29
      相关资源
      最近更新 更多