How can I play two or three vibrates in a row? Or different patterns of vibrate?
Repeating AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) does not work. Only does a single vibrate.
Tried using callback
OSStatus AudioServicesAddSystemSoundCompletion (
SystemSoundID kSystemSoundID_Vibrate,
CFRunLoopRef inRunLoop,
CFStringRef inRunLoopMode,
AudioServicesSystemSoundCompletionProc vibrationDone,
void *inClientData
);
but it does not trigger vibrationDone.
Try registering a callback using AudioServicesAddSystemSoundCompletion to be notified when the vibrate "sound" has ended before attempting to play it another time. From the docs:
Because a system sound may play for several seconds, you might want to know when it has finished playing. For example, you may want to wait until a system sound has finished playing before you play another sound.
NB: I haven't tried if this actually works.
Related
I need my software to wait until the sound is completely played before proceeding.
I've got a lot of sounds to develop, so using the callback method will take a lot of development time.
Is there a way to call AudioServicesPlaySystemSound and have it block until it completes playing, without using the callback method?
You can't - you have actually no exact control of when your sound exactly start and finish. Also not that the sound is played in a background thread for the AudioServicesPlaySystemSound API. I have read this article recently for playing sound on iOS take a look at it. You might want to use an other API for playing your sound.
Im implementing a fake call app.Im using a NSTimer for checking the time and it is working fine.The problem is when we press the sleep button,only vibration is working but ring tone is not playing.I tried this code but still ring tone is not playing.
AudioSessionSetActive(true);
// Set up audio session, to prevent iPhone from deep sleeping, while playing sounds
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (
kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory
);
How can i solve this issue.please help.Thanks in advance
I am sorry but I think You can not show calling screen while device locked (deep sleep). The only way is to fire local notification to wake up your application manually by user. Something like : You have fake call now. Do you want to receive ? So when user press Yes and it will open your application and you will need to handle to show calling screen in appDelegate background methods.
I played with other Fake Call apps and they are doing same. We are not allowed to do any UI Changes in background. So this is the only way to achieve your goal to display calling screen.
Hope this help.
Edit:
I am not sure why vibrate is working. Did you set below property in your info.plist file ? Just to give it try. Not sure that will solve your problem. Just give it a try once. See attache picture. Set Required Background modes to App Plays Audio.
Could someone help me with a function that fires multiple AVAudioPlayers at the same time? Right now I am trying to get a total of twelve AVAudioPlayers to fire at once if twelve buttons are activated, but there is a delay and it sounds like someone is running their finger down a piano instead of hitting all the keys at once.
I've looked at Audio Queue Services and can't understand how to actually implement that into code, but it says it can play synchronized sounds. I'm not sure sure how to set all of it up. I'm trying to remake a Tone Grid app.
Why don't you use http://www.hollance.com/2011/02/soundbankplayer-using-openal-to-play-musical-instruments-in-your-ios-app/
There you have a polyphonic player, beautifully coded and ready to rock!
I used it in my first app a while back: http://itunes.apple.com/gb/app/chordwheel-pro/id406836326?mt=8
Are you calling the method prepareToPlay on all 12 AVAudioPlayer instances. From the docs: "Calling this method, preloads the buffers and acquires hardware, to minimize delay."
See the AVAudioPlayer class reference.
I have set up an AVAudioPlayer object in viewDidLoad, as per the Apple guidelines, calling prepareToPlay as the last line in viewDidLoad (i have tried in awakeFromNib also).
When i press my play button, there is a pause, as it would appear to load the file, then it plays.
In audioPlayerDidFinishPlaying, i reload the player with a different sound, and when clicking play for a second time, the file plays instantly.
What would cause the player to lag on the first play?
Thanks.
The delay is due to AVAudioPlayer being initialised. Please see this answer.
The audio system runs on several asynchronous software processes (audio units, OS drivers, etc.) and hardware systems (DMA, DACs, audio amp power supplies, etc.) that never really all completely finish initialization until some sound is actually played all the way out the speakers or earphones.
Here's one method to do that: Create a sound file containing a half second of silence. On app start up, while your app and view controller are still loading, use AVAudioPlayer to play this file of silence. Now when your view finishes loading, AVAudioPlayer should be ready to play subsequent non-silent sounds much faster, since some audio (silence) has already already gone all the way out to the speakers.
What kind of sound are you playing? Alerts, something longer? If alerts, I did go this way and it's much better with lags ...
create system sound with AudioServicesCreateSystemSoundID
play system sound with AudioServicesPlaySystemSound
dispose system sound with AudioServicesDisposeSystemSoundID
... you only need to store SystemSoundID for each sound you would like to play.
I've created a few sounds for use in my game. I can play them at certain events without issue:
// create sounds
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle();
_soundFileShake = CFBundleCopyResourceURL(mainBundle, CFSTR("shake"), CFSTR("wav"), NULL);
AudioServicesCreateSystemSoundID(_soundFileShake, &_soundIdShake);
// later...
AudioServicesPlaySystemSound(_soundIdShake);
The game has a mechanism which allows you to shake the device to activate some functionality. I've got the shaking code done so I get get a "shaking started" and "shaking ended" message to my game. What I need to have happen is start playing "shave.wav" when shaking starts and loop it until it stops. Is there a way to do this with AudioToolbox/AudioServices? How could I do this if not?
Keep track of the "is shaking" state and register a callback for system sound completion with AudioServicesAddSystemSoundCompletion. Then just start the system sound again whenever it completes AND the device is still being shaken. If the sound is short enough, this will create the desired effect. If you need to ensure the sound stops immediately when the shaking stops, you'll need to use one of the sound APIs that provides more granular control over playback (e.g., Audio Queue Services or AVAudioPlayer).