Audioservicesplaysystemsound Audio Service-Standby

Source: Internet
Author: User

For simple, no-mix audio, the Avaudio Toolbox Framework provides a simple C-language-style audio service. You can use the Audioservicesplaysystemsound function to play simple sounds. Here are a few rules to follow:

1. Audio length less than 30 seconds

2. The format can only be PCM or IMA4

3. File must be stored as. CAF,. AIF, or. wav format

4. Simple audio cannot be played from memory, but only by disk files

In addition to the restrictions on simple audio, you have virtually no control over how audio is played. Once the audio is played, it starts immediately and is the volume playback that is set by the current phone user. You won't be able to loop through the sound or control the stereo effect. However, you can still set a callback function to be called at the end of the audio playback, so you can clean up the audio object and notify your program to end.

Directly on the code:

  1. #Import <AudioToolbox/AudioToolbox.h>
  2. #Import <CoreFoundation/CoreFoundation.h>
  3. This function is called when the audio is finished playing
  4. static void soundfinished (Systemsoundid soundid,void* sample) {
  5. / * Play all over, so release all resources * /
  6. Audioservicesdisposesystemsoundid (sample);
  7. Cfrelease (sample);
  8. Cfrunloopstop (Cfrunloopgetcurrent ());
  9. }
  10. Main loop
  11. int main () {
  12. / * System audio ID to register the sound we are going to play * /

Audioservicesplaysystemsound Audio Service-Standby

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.