开发者

AVAudioRecorder File won't play except with VLC

开发者 https://www.devze.com 2023-01-14 13:13 出处:网络
Ok. I think I\'m missing something here and I\'m new to Core Audio but I have scoured the Apple documents and the rest of the web to no avail. I\'ve also posted this same question to the apple dev for

Ok. I think I'm missing something here and I'm new to Core Audio but I have scoured the Apple documents and the rest of the web to no avail. I've also posted this same question to the apple dev forums and got no replies. I'm hoping the StackOverflow community can help me out.

I'm recording audio and playing it back just fine using AVAudioRecorder and AVAudioPlayer. My app also uses file sharing so the user can export the audio and play it elsewhere. This is where my issue comes in. I'm recording using AAC encoding but the file will not import into iTunes. It plays fine using VLC and looking at the media information its' codec is mp4a which I expected.

Reading on the web its sounding like the AAC needs a mp4a wrapper. Can anyone enlig开发者_开发技巧hten me or direct me to some info on this? Possibly an API or 3rd party library I can use?

I've played with the SpeakHere and ExtAudioFileConvertTest examples, added file sharing, recorded as AAC but they still won't play in iTunes.

Here's my recording code. Very grateful for any suggestions or guidance. Thanks!

 NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
      [NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
      [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
      [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
      [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,
      nil];

     ...     


NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL: soundFileURL
                               settings: recordSettings
                                error: &error];


Figured this out with some help from some on the Apple forums. All I had to do was set the filename extension to m4a! Changing the extension manually and trying to play in iTunes does not work. Something under the covers in AVAudioRecorder seems to use the extension to encode the file correctly. Just set the extension correctly and it works beautifully. Hope this helps someone else out in the future.

0

精彩评论

暂无评论...
验证码 换一张
取 消