Eli Waxman
Eli Waxman

Reputation: 2897

Sound wont play in button press

the code I'm using to play the sound is this:

NSString *soundFilePath = [NSString stringWithFormat:@"%@/%@.m4a", [[NSBundle mainBundle] resourcePath],currentSound.soundNameID];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 0;

[player play];        

I'm trying to play the sound but it wont play. my file is a m4a type.

Upvotes: 0

Views: 85

Answers (2)

sheraza
sheraza

Reputation: 511

if soundFileURL is OK, then I think the problem is that player is released before playing sound, declare player in header file.

Upvotes: 1

David Hoerl
David Hoerl

Reputation: 41642

Add abn assert after each object creation to look for a nil object. Also don't do this in the button selector, put it into a block you dispatch to the main queue.

Upvotes: 0

Related Questions