Fade In and Out Audio in iPhone SDK - iphone

I am wondering if there is some way to fade in and out audio using AVAudioPlayer in CocoaTouch, with a pause command once the music finishes fading and then a play command once the fading begins. I have heard that one can use NSTimer for this purpose, but I am unsure of the easiest way to accomplish this.
Thanks for any help!

There is a good video tutorial to do this here: Playing a sound, and fading a sound using AVAudioPlayer on iPhone.

Related

Audio file cannot be played on watchOS after background

When playing an audio file in watchOS (using SpriteKit):
run(SKAction.playSoundFileNamed("ready.wav", waitForCompletion:false))
It will works until you background the app (says face the watch outwards) and back, then the audio file cannot be played anymore.
I have tried many workarounds, including setting UIBackgroundModes to audio, but the sound will always stop working after the app is background and back. Any solution?
PS: I think I might have found the answer: use AVAudioPlayer instead of SKAction.
You need to start HKWorkoutSession and in info.plist enable workout background processing. Don't need the audio to play in background, just continue to play once it comes back from background.
Use AVAudioPlayer instead of SKAction. This works.
Only SKAction.playSoundFileNamed has this issue.

Play custom sound while vibration on iPhone

In my iPhone application I need to play custom sound while vibration.
I have found here: http://gregheo.com/blog/simple-audio/ that I should use AVAudioPlayer. But how can I play system sound of vibration using AVAudioPlayer? If there is another way to play custom sound and vibration together?
Update
I have found that I can use AVAudioPlayer to play custom sound and Audiosession to play vibro system sound. But maybe someone can advise me a better solution?
This SO post seems to deal with the exact opposite of your issue so it might give you the answer you are looking for:
How to play system sound on iOS without vibration?

How to play 2 sounds simultaneously

I have to play 2 sounds in my app...one for background and one for when user clicks any button.....Not i have only one sound for background and too many sounds for that button click.....all sounds are in mp3 format....
I am using AVAudioPlayer to play these sounds...
My questions are
1- Can i play these 2 mp3 sounds at same time Or should i convert that background sound to any other format....
2- I am using AVAudioPlayer to play these sounds.....so can i use 2 instances of AVAudioPlayer in same class......
Please Note that i want that background music continuously playing.....
Please help....
1., Yes, you can even more..
2., Yes you can use AVAudioPlayer to play these, each sound source have to be allocated separately.
If you have short sounds that does not need to be stereo, you can use system sound framework to make them play.
Have a look to below look, will helpful for you.
2 mp3 sounds at the same time in iphone?
and blog tutorial
http://brainwashinc.wordpress.com/2009/08/14/iphone-playing-2-sounds-at-once/

Is there a standard way of playing longer sound clips?

I'm currently using AudioServicesPlaySystemSound(_soundID) to play sound clips. My understanding is that this can only be used to play clips under 30 seconds.
What is the standard way of playing longer sound clips?
AVAudioPlayer

How can i use more them one sound simultainiously in iphone application using cocos2d?

Duplicate:
use more then one sound in my iphone application using cocos2d
Hi,
All of the member of this forums.I need to help yours for doing my game project.I want to play some sound in my gaming project.When this game is started a background sound is playing continuously until the game is stop (exit). When game is played that time some action button are work and every action one sound is play for few second but background sound did not stop that time. How can i do this if anyone have a solution than reply with answer please.
If you are using cocos2d 0.82, then you can use denshion for this.
Play background music:
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:#"somemusic.mp3"];
Play SOUND EFFECT:
[[SimpleAudioEngine sharedEngine] playEffect:#"mysound.wav"]
You can find this and more at http://www.cocos2d-iphone.org/wiki/doku.php/cocosdenshion:cookbook
You could, if you implemented your own mixer. Just playback a buffer and mix the audio yourself. It' basically boils down to just averaging two different amplitudes. In some cases it's a bit more advanced.
Check out the AVAudioPlayer class. It will do what you need.
One thing to be aware of is that this class will only play one mp3 format sound at one time. I suggest converting to IMA4 format if you are using mp3 and need to play multiple sounds at once.
You can use the afconvert command to convert between sound file formats.
AVAudioPlayer is available in firmware 2.2+.