iOS about audio playback research

Due to the recent work in audio, I have researched some knowledge about audio playback, and I have gone through a lot of detours in the middle. I hope this small episode can give some inspiration to the students who pay attention to us and take less detours. Finally, here is the information I have seen. Here is a brief summary of audio playback. There are 5 ways to play audio in iOS (if you have more, I'd appreciate it) and they are used in different scenarios.

[1] Play audio less than 30s:
AudioServicesPlaySystemSound can play audio less than or equal to 30s, mainly used to play some prompt sounds, you can use the value of AudioServicesPlaySystemSoundWithCompletion to play the completed callback. It has the following features:

- Use the system volume, you cannot modify the playback volume;
- Start playing immediately, and cannot be paused;
- Does not support fast-forward playback, nor can it play in a loop;
- Only one audio can be played at a time;
- Only through the mobile phone To play audio, it cannot be output through other devices, for example, it cannot be played through the car.

See more system sound IDs: web link

[2] AVAudioPlayer plays local audio, or audio streams that have been loaded into memory, mainly used to play some local audio files. Note that it cannot play network audio. It has the following features:

- Play from any position, fast forward, rewind;
- Play in a loop;
- Play multiple audios at the same time;
- Control the playback rate;

[3] AVPlayer can play local and network audio, and also It can play video, and it supports streaming media playback, which means that we can use it for use scenarios that are played while playing.

[4] AVQueuePlayer is a subclass of AVPlayer, it contains a queue, mainly used to play an audio and video queue.

[5] Audio Queue is mainly used to play audio and recording. It is relatively low-level and will have more control. If the main function of the APP is based on audio playback, it is recommended to use this.

In general, if you want to play ordinary local audio, you can choose AVAudioPlayer, which can achieve a basic playback without knowing more audio knowledge; if you want to do streaming media playback, it is recommended to use AVPlayer + Local Server. Similar to the way Singba is currently open source. Of course, you can also choose Audio Queue, but this is more difficult and requires an overall understanding of audio playback. It is recommended to use the three-party library FreeStream, but some knowledge of C++ is required, because there are some pits that need to be filled in the use process, so you have to read source code. Finally recommend some good articles. Official

Audio  Queue  : Web Link
Official  AudioSession  :  Web Link



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939569&siteId=291194637