I am using XCode 7 with iOS 9 and I am trying to play a sound. I have been googling for a solution for days and I have tried every possible solution out there and nothing is working.
Here is my code
.h
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController <DTDeviceDelegate, AVAudioPlayerDelegate>
{
}
and here is my .m file:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"autumn_leaves" ofType:@"m4a"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
error:&error];
player.numberOfLoops = -1; //Infinite
[player play];
and no sound, no errors, no warnings nothing at all
soundFilePath and soundFileURL are not nil, same with player, they are getting populated. My phone volume is as loud as it can be.
I have also tried in .m file:
@property(strong, nonatomic) AVAudioPlayer *player;
self.myPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL error:&error];
[self.myPlayer play];
Also did not play sound and no errors.
Here is a screenshot of my Resources folder:
Please Help!
