Play audio files
During a call or live broadcast, in addition to the voice of the user speaking, sometimes it is necessary to play a custom voice or music file andLet other people in the channel hear, such as the need to add sound effects, or need to play background music, etc. Cloudhub providesThe following methods can meet the needs of playing sound effects and music files.
Before you start, make sure that you have implemented basic real-time audio and video functions in your project. For details, see Start an
audio and video callor Start an
interactive live broadcast
Sound effects usually refer to audio with a short duration. The method of playing sound effect files is mainly used to play short ambient sounds, such as clapping, game bulletsImpact sounds, etc., can play multiple sound effects superimposed, and the sound effect files can be pre-loaded to improve performance.
CloudHub SDK provides unified management of sound effects, including some common methods for managing sound effects. The sound effect is specified by the audio file path,SoundId is used internally to identify and process sound effects. The sound effect files are usually saved locally or on the network; the SDK does not mandate how to determineThe meaning of soundId is to ensure that each sound effect has a unique identification. The general practice is to increase the id and use the name of the sound effect filehashCode, etc.
Preloading is not a necessary step. Generally speaking, in order to improve performance or need to repeatedly play a specific sound effect, IWe recommend using preloading. However, if the sound effect file is relatively large, preloading is not recommended.
You can call this method multiple times to play multiple sound effects at the same time. It is recommended to play up to three sound effect files at the same time