2010-07-06 4 views
0

im nouveau développeur et faire ma première application iPhone, et je veux faire bouton pour on/off multiplesounds, exemple quand j'appuie sur le bouton pour plusieurs sons après quand je joue sons il joue tout le son en même temps et si son off ne peut jouer qu'un seul son, quel code doit faire jouer ON/OFF plusieurs sons?iPhone, AVAudioPlayer et multiplesound

désolé pour mon mauvais anglais, Réservoirs!

Répondre

1

Sania,

Pour jouer plusieurs sons à la fois, Apple recommande d'utiliser le format .caf qui est matériel décodé. En outre, vous créez simplement un nouvel objet AVAudioPlayer pour chaque fichier audio au lieu de réutiliser le même objet dans le cas où vous ne voulez qu'un seul son à la fois.

Je ne vais pas entrer dans une grande partie du code car il y a déjà beaucoup là-bas si vous recherchez juste pour ... mais voici quelques liens utiles pour vous aider à démarrer:

http://developer.apple.com/iphone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

http://www.mobileorchard.com/easy-audio-playback-with-avaudioplayer/

// a function I use to play multiple sounds at once 
- (void)playOnce:(NSString *)aSound { 

// Gets the file system path to the sound to play. 
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"]; 

// Converts the sound's file path to an NSURL object 
NSURL *soundURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; 
self.soundFileURL = soundURL; 
[soundURL release]; 

AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error:nil]; 
self.theAudio = newAudio; // automatically retain audio and dealloc old file if new file is loaded 

[newAudio release]; // release the audio safely 

// buffers data and primes to play 
[theAudio prepareToPlay]; 

// set it up and play 
[theAudio setNumberOfLoops:0]; 
[theAudio setVolume: volumeLevel]; 
[theAudio setDelegate: self]; 
[theAudio play]; 

} 
Questions connexes