demand

As for the numerous audio and video frameworks in the entire iOS system, we should not blindly choose. For the collection and recording of audio and video, we need to choose the MOST suitable API for the project according to our actual needs, so as to accomplish the project tasks most efficiently.

The following is the selection of some main middle and low level framework recommendation and principle, code practice, you can learn what you need through the following link, you can also find the corresponding article from the link in the article, go to Github to download the corresponding Demo to help you develop quickly.


Audio architecture in iOS

1. The upper API

For just want to directly play an audio or video demand, there is no need to use the underlying API, these API can simply directly call some similar start,stop, set some resource file path can do recording and playing.

  • Video :AVPlayer
  • Video recording :UIImagePickerController
  • Audio :AVAudioPlayer
  • Audio recording :AVAudioRecorder

Above API if you need to understand the use of their own Baidu, easy to use.

2. Middle API

If you want to capture video frames and make use of audio frames, you need to use some mid-level APIS. For collection, the bottom layer of video is AVCaptureSession. We can get the audio and video in the specified format through the callback function. The same is true for recording. However, for audio, if there are not too many specific Settings for audio and only synchronization, you can directly use audio collection in AVCaputureSession.

  • Audio and video collection: AVCaptureSession

    • Principle: digging gold, Jane book, blog
    • Actual combat: digging gold, Jane book, blog
  • Audio and video recording: AVAssetWriter AVCaptureMovieFileOutput – the nuggets, Jane books, blogs

3. Low-level, most functional API

For Audio collection, you can also use a lower-level, more useful Audio Queue, Audio Unit.

  • Audio collection/playback: Audio Queue, Audio Unit
  • Audio File – Jane Books, Nuggets, blog

Select the Audio Queue and Audio Unit

  • Audio Queue: Collects Audio data efficiently in the form of a Queue. You can directly set the collection of PCM,AAC and other compressed and uncompressed Audio data.
    • Principle: digging gold, Jane book, blog
    • Actual combat: Jane book, blog, digging gold
  • Audio Unit: Provides more professional Audio processing than Audio Queue, supporting mixing, balancing, format conversion and real-time input/output for recording, playing, offline rendering and real-time conversations, such as voice over Internet Protocol (VoIP). It can be dynamically loaded and used from iOS applications.
    • Principle: digging gold, Jane book, blog
    • Actual combat: digging gold, Jane book, blog