Sending a Value to an AVAudioPlayer Object to Play a Different Sound - iphone

I have an iphone app where I am playing a sound with one button using an AVAudioPlayer object. However, I would like to use a variable for the sound name and send a value to that variable. I have two other buttons that play different sounds and would like to send the sound name values to the variable that is in the AVAudioPlayer. How do I do that?
Thanks!

you can keep your audio files (in resource) with numeric names such as 1.mp3, 20.mp3, 41.wav etc and then you can use [NSString stringWithFormat:#"%d.mp3",soundId]; to generate sound file name to use generating absolute resource path and pass it to AVAudioPLayer
Best of Luck!!

This cannot be done. Create a new AVAudioPlayer for each new sound. If you wish to interrupt the current sound, send stop to the current instance.

Related

playing multiple sounds(mp3, wav etc) in an iOS app

This is my requirement. I have set of audio files(mp3, wav mostly). My app's interface will have a list of these sound names and a toggle ON/OFF switch for each of the sound item. On switching a sound ON it should start playing and vice versa. If more than one sound is ON then they should be played simultaneously. I can switch any sound ON/OFF while the sound is playing and it should switch off instantly.
What classes are best suggested for this behavior ? Do I need to mix the sounds etc or just instantiate multiple AVAudioPlayer instances ???
Please guide me in making an efficient app.
Thanks!
Use different instance of AVAudioPlayer for playing simultaneously.
Now maintain list of AVAudioPlayer instance into NSMutableArray depending on state ON/OFF. if state ON then play audio add AVAudioPlayer instance in array and if state OFF then stop audio remove AVAudioPlayer instance from array.
You can user openAL to do your task. Here is the link to get it https://github.com/kstenerud/ObjectAL-for-iPhone .

Combine two audio files together and play them in iPhone

I do not want any code but want to get a reference about my question mentioned below...
There is background music available and there is recording option in my app...
Once I start recording , application records my sound and when play button clicks , It will play the recording along with the background music...
I had use this Link but can not get as I want...
I think there is a mechanism like merging two audio files and make it one before playing....
How can I achieve this by coding... Is there any reference link or any sample code available?
Thnx in advance...
Most people mistake the one instance of AVAudioPlayer as the unit that plays the sound directly, but it doesnt. Mixing is done by the OS, not by the instance of AVAudioPlayer.
With other words:
No one says you can't have more then one AVAudioPlayer.
Create one for you background and let it play. Create another instance of AVAudioPlayer for you recorded sound and let it play. Voila

want to create an audio playlist dynamically by using ".plist" file an then want to play it in iphone in built audio player

I want to create an audio playlist dynamically by using ".plist" file an then want to play it in iphone in built audio player. But during creation of audio list in plist there is no option in "type" to select data type for audio file.
Plz guide any one what approach I should follow ?
I'm not sure if I understood your question correctly. Can you specify what APIs you are using and what you are trying to do with more detail?
As far as Property Lists go, they are very generic so there wouldn't be anything for audio files in particular. You could specify the data type as a string.
How to approach this: First of all, you need to read the list into an NSArray and use that to generate a table view with your track listing (use tableView:didDeselectRowAtIndexPath: to start playing a track upon the user selecting it). To play a track use AVAudioPlayer.

record and play the same file

I am trying to record the audio using AVAudioRecorder. My problem is i want to play the file while it is being recorded. Is there any way i can do this? I have set the category to PlayAndRecord. I have created the file for recording.
I have tried to initialize both the recorder and the player for the URL and tried to play the file after the record function. But it seems that only one chunk of the file gets played.
I seriously doubt you can do this with AVAudioRecorder and AVAudioPlayer convenience classes.
The AVAudioPlayer assumes that the file it plays is static and complete. For example, it has no method to dynamically update the track length. It reads the track length once at startup and that is why only the initial chunk of the file gets played. Any modifications to the file made after the AVAudioPlayer instances opens the file are ignored.
You'll need to set up a custom audio queue if you want to get fancy.
As an aside, how do you plan on getting around feedback problem of caused by recording what you are playing? You have nothing but a shrieking squeal in very short order.

Playing audio that is retrieved from url

I am getting a list of songs and its corresponding images from a url.The url is a json url. When i click the list a corresponding song is played. I have used AVFoundation Framework to play the song. Now the issue is that i need to play the next song after the playing of first song is completed. The corresponding images also must load. If i click the next or previous button the corresponding songs must be played. What is the best possible mechanism to attain it???
I have read about the Audio Queues and Audio Units but not sure how to use them. I'll be really helpful if i am provided with some sample code of how to do it.
The easiest thing is to just place an If statement in audioPlayerDidFinishPlaying which is what is called after each sound is played (if playing them with an AVAudioPlayer).
You can also use that to update whatever images you need to as well based on the name.