AVAudioPlayer gives no sound output
Yes, ARC was the problem for me too. I solved just adding:
In .h
@property (strong, nonatomic) AVAudioPlayer *player;
In .m
@synthesize player;
-(void)startMusic{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Riddls" ofType:@"m4a"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = -1; //infinite
[player play];
}
Updated answer:
I've got the issue. It's with ARC and has nothing to do with prepareForPlay. Simply make a strong reference to it and it will work.
as stated below by user: Kinderchocolate
:)
In code:
.h
~
@property (nonatomic, strong) AVAudioPlayer *player;
.m
~
@implementation
@synthesize _player = player;