开发者

How to play sound on "Ringer & Alert Volume" level

In my app I want to have an alarm/notification on "Ringer & Alert Volume" level.

In other words on the volume level which phone rings or alarms are used on (Preferences/Sound/Ringer and Alerts). It is different from the system volume level which changes with the volume buttons.

It should also play more than 30 sec.

I know it's possible because some clock apps can do that.

UPDATE: OK I found an unideal solution. If use AudioServicesCreateSystemSoundID and load my own sound file (aif, wav, etc no mp3 or other compressed audio) than it works. The only problem is that it has to be 30 sec or shorter, but I can can cut it 开发者_运维问答into 30sec pieces and play them piece by piece.

It does not work when on silent switch on which is a problem for me.

Code:

    SystemSoundID mySound;
    AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mySound"), CFSTR("aif"), NULL), &mySound);
    AudioServicesPlaySystemSound(mySound);

I suspect that OpenAL should do that. Does anyone has a simple example which loads a aif/wav file and plays it on iPhone. I found some complicated examples, but all I need is just play and stop a sound (even if it's leaking that's fine).


I found it out myself. I have to use AudioServicesCreateSystemSoundID and load my own sound file (aif, wav, etc no mp3 or other compressed audio) The only problem is that it has to be 30 sec or shorter, but I can can cut it into 30sec pieces and play them piece by piece.

It does not work when on silent switch on

Code:

    SystemSoundID mySound;
    AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mySound"), CFSTR("aif"), NULL), &mySound);
    AudioServicesPlaySystemSound(mySound);


You should look into AVAudioPlayer class. It will allow you to play sound files of any duration and you can control the volume output for the specified files you wish to play. I'm not in front of my mac otherwise I would provide code. Let me know if you need further instruction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜