LoginSignup
2
1

More than 1 year has passed since last update.

[保存版] AVAudioRecorderのAVFormatIDKeyの指定方法まとめ

Posted at

以下は対応するAVFormatIDKeyとファイル拡張子の組み合わせです。

mp3: kAudioFormatMPEGLayer3
m4a: kAudioFormatMPEG4AAC
aiff: kAudioFormatLinearPCM
caf: kAudioFormatAppleLossless
wav: kAudioFormatLinearPCM

コード内で使用する場合は、以下のように記述します。

let fileExtension = "mp3"
let formatID: AVAudioFormatID

switch fileExtension {
case "mp3":
    formatID = kAudioFormatMPEGLayer3
case "m4a":
    formatID = kAudioFormatMPEG4AAC
case "aiff":
    formatID = kAudioFormatLinearPCM
case "caf":
    formatID = kAudioFormatAppleLossless
case "wav":
    formatID = kAudioFormatLinearPCM
default:
    formatID = kAudioFormatLinearPCM
}

// ここから先は formatID を使用して AVAudioRecorder を設定する処理が続く

このように、ファイル拡張子に対応するAVFormatIDKeyをswitch文で判別することで、それに対応したAVAudioRecorderを設定することができます。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1