iphone开发 播放短声音

在iphone开发中我们有时候需要播放短音提示用户的操作,iphone api提供了简单的播放短音类,具体实现方法如下

    //播放声音变量
    CFURLRef soundFileURLRef;
    SystemSoundID soundFileObject;
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR("page"), CFSTR("aif"), NULL);
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
    //播放声音
    AudioServicesPlaySystemSound(soundFileObject);
    //销毁变量释放内存
    AudioServicesDisposeSystemSoundID(soundFileObject);
    CFRelease(soundFileURLRef);
posted @ 2011-06-26 15:09  fighter  阅读(533)  评论(0编辑  收藏  举报