• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
AVAudioPLayer Loop Issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AVAudioPLayer Loop Issue


  • Subject: AVAudioPLayer Loop Issue
  • From: email@hidden
  • Date: Thu, 22 Sep 2011 19:46:01 -0500

Hi

I am building a button based app that has a button for each of 15 sounds. Each sound is triggered by a button and played back through its dedicated AVAudioPlayer.

The app works fine except it is possible to retouch a button just as its sound is ending and it will not replay.

Just to try and describe my problem again

  • touching a button plays a sound and sets the numberOfLoops = -1

  • releasing that button sets number of loops = 0 so that the files always plays in "one shot" mode

Touching again should reset it and make it repeat. it usually does this unless you retouch right as the sound ends.

So its almost like there is contention between the AVAudioPLayer numberOfLoops messages.

The sound files I use are short all between 1 and 4 seconds.

The reason I am using the numberOfLoops messages is so that the sound file minimally plays once through. If you continue to press the button it plays thorough again a second time as you would expect, on and on etc  When you touch up,  the file should complete and then stop playing. You should be able to press that button again before it ends and reset the number of loops so that it repeats again. It does this most of the time. Repressing the finger right as the sound file is completing and it does not replay. lifting the finger and touching the button again and it plays.


I would appreciate any ideas that you may have to fix this even if it means that I need to take a different approach.

Thank You


Chris

Here is the relevant parts of my code:

- (void)viewDidLoad {
[super viewDidLoad];
[self initPlayers];

}

- (void)initPlayers{
NSString *p;
NSURL *f;
NSArray *snd;
AVAudioPlayer *a;
snd = [NSArray arrayWithObjects:@"file01",@"file02",@"file03",@"file04",@"file05",
  @"file06",@"file07",@"file08", @"file09", @"file10", @"file11", 
  @"file12",@"file13", @"file14", @"file15", nil];
players = [[NSMutableArray alloc]init];
for (int i = 0; i < 15; i++) {
p = [[NSBundle mainBundle]pathForResource:[snd objectAtIndex:i]ofType:@"wav"];
f = [[NSURL alloc]initFileURLWithPath:p];
a =  [[AVAudioPlayer alloc]initWithContentsOfURL:f error:nil];
   
[a setDelegate:self];
[a prepareToPlay];
[players addObject:a];
[f release];
[a release];
}
}

- (IBAction)buttonPressed:(id)sender
{
AVAudioPlayer *soundPlayer;
int i = [sender tag] - 1;
soundPlayer = [players objectAtIndex:i];
soundPlayer.numberOfLoops = -1;
[soundPlayer play];
}

- (IBAction)buttonReleased:(id)sender
{
AVAudioPlayer *soundPlayer;
int i = [sender tag] - 1;
soundPlayer = [players objectAtIndex:i];
soundPlayer.numberOfLoops = 0;
}


- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)audioPlayer successfully:(BOOL)flag
{
[audioPlayer prepareToPlay];
}



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: iPad USB Audio Output
  • Next by Date: Re: iPad USB Audio Output
  • Previous by thread: Integer Mode in Lion
  • Next by thread: ExtAudioFileRead ioNumberFrames parameter can only be adjusted downward?
  • Index(es):
    • Date
    • Thread