如何播放短的声音 如按键声音

System Sound Services Reference


Framework

AudioToolbox/AudioToolbox.h

Declared in

AudioServices.h

Overview

System Sound Services provides a C interface for playing short sounds and for invoking vibration on iOS devices that support vibration.

You can use System Sound Services to play short (30 seconds or shorter) sounds. The interface does not provide level, positioning, looping, or timing control, and does not support simultaneous playback: You can play only one sound at a time. You can use System Sound Services to provide audible alerts. On some iOS devices, alerts can include vibration.

For usage information for iOS, refer to “Using Audio” in Multimedia Programming Guide.

Functions by Task

Creating and Disposing of System Sound Objects

  • AudioServicesCreateSystemSoundID
  • AudioServicesDisposeSystemSoundID

Playing Sounds

  • AudioServicesPlayAlertSound
  • AudioServicesPlaySystemSound

Adding and Removing System Sound Callbacks

  • AudioServicesAddSystemSoundCompletion
  • AudioServicesRemoveSystemSoundCompletion

Managing System Sound Services Properties

  • AudioServicesGetPropertyInfo
  • AudioServicesGetProperty
  • AudioServicesSetProperty


例子


SystemSoundID plop_id, batt_id;


    CFURLRef plop_url  = CFBundleCopyResourceURL (CFBundleGetMainBundle(),

                                                  CFSTR ("plop"),

                                                  CFSTR ("wav"),

                                                  NULL);    //plop.wav是添加到bundle的声音文件

    // Create a system sound object representing the sound file

    AudioServicesCreateSystemSoundID (plop_url, &plop_id);

   CFRelease(plop_url);

 

   AudioServicesPlaySystemSound(plop_id); //播放声音


   //最后在dealloc中,释放资源

   AudioServicesDisposeSystemSoundID (plop_id);





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值