【问题标题】:post audio file from document to server将音频文件从文档发布到服务器
【发布时间】:2014-05-01 11:31:13
【问题描述】:

您好,我正在创建一个录制音频的演示应用程序。我已按照本教程进行操作

Link to tutorial

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

录音部分工作正常,应用程序正在播放音频文件,

问题: 如何将录制的文件发布到服务器。

【问题讨论】:

  • 你实现了webservice吗?
  • 您可以使用 ASIHttpRequest 或任何其他框架将您的 outputFilePath 上传到服务器。参考allseeing-i.com/ASIHTTPRequest
  • 如果问题是“如何上传文件?”为什么要写所有这些员工?请关闭此工单并打开更具体的工单。
  • 好吧,我展示了我是如何录制声音的,现在我想把它放到服务器上,音频文件保存在文档中,是的,我已经实现了 Web 服务,目前它正在发送一个 id,我该如何发送完整的音频文件?

标签: ios avfoundation avaudiorecorder


【解决方案1】:

您可以使用以下示例:

NSURLSession *session = [NSURLSession sharedSession];
[[session uploadTaskWithRequest:[NSURLRequest requestWithURL:your_url]
                      fromFile:file_url
             completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

             }] resume];

请在此处阅读更多内容http://www.raywenderlich.com/51127/nsurlsession-tutorial

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-07
相关资源
最近更新 更多