views:

1400

answers:

1

When I run this sample code on a 2nd generation IPod touch with OS version 3.0, it works fine. However when I run it on a 1st generation IPod touch with OS version 2.2.1, it doesn't. I am playing an mp3 for my background music but it still plays the SFX mp3 on the 3.0 device just fine. I am wondering if something has to be done differently for older devices/os versions or if the older devices/os versions can't play multiple mp3 files at the same time. Posts I have read say that the IPhone can't play multiple mp3 files at the same time but it is working on the 3.0 device. Ideas?

//h file
@interface AudioTest {
 AVAudioPlayer *player;
}

@property (nonatomic, retain) AVAudioPlayer *player;

- (void)playSound;


//m file
@synthesize player;

- (void)playSound {
 NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sound"     ofType:@"mp3"];

 NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];

 AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL     error:nil];

 [fileURL release];

 self.player = newPlayer;

 [newPlayer release];

 [self.player prepareToPlay];
 [self.player setDelegate:self];
 [self.player play];
}
A: 

Playing more than one MP3 file at a time has never worked reliably for me prior to the 3.0 OS release.

Mark Bessey