PDA

View Full Version : Playing a sound > 30sec just doesn't work for me




holycow
Jan 21, 2009, 07:32 PM
I cannot for the life of me get an mp3 file to play using AVFoundation and it is driving me crazy. It's not that much code. The code will compile without problems and when I run it in the 2.2 Simulator, no sound comes out. Would someone mind posting a sample xcode project or some code that is confirmed to be working and plays a single audio file? I have no idea if this is my setup or what. I can play shorter system sounds just fine.

I'm just using this sample code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"dream" ofType:@"m4a"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];



dejo
Jan 21, 2009, 07:43 PM
You sure you meant:
pathForResource:@"dream" ofType:@"m4a"
and not
pathForResource:@"dream" ofType:@"mp3"
?

holycow
Jan 21, 2009, 07:49 PM
yeah, that's not the problem. does the simulator just not play sounds like that? I haven't gotten a chance to try it on a device, but I figured it wouldn't since it's not working in the simulator.

holycow
Jan 21, 2009, 08:11 PM
Ok, I got it to work on my actual iPhone, but the simulator just freezes up. It does that with other sample xcode projects that play sounds too. Weird.