I searched, and I believe that my problem is completely unique. I know about Simulator 5.1 error when using AVAudioPlayer, which is not my problem. I am working on an iOS 5.1 device.
Here is my header file:
#import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <AVFoundation/AVAudioPlayer.h> -(IBAction)pushBell; @end
and my implementation file:
#import "BellViewController.h" @interface BellViewController () @end @implementation BellViewController -(IBAction)pushBell { NSString *soundPath =[[NSBundle mainBundle] pathForResource:@"bell1" ofType:@"caf"]; NSURL *soundURL = [NSURL fileURLWithPath:soundPath]; NSError *error; AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error]; [theAudio setDelegate:self]; [theAudio setNumberOfLoops:0]; [theAudio play]; } @end
And I have a button in my .xib that plays the file.
So that I refer to my audio file correctly, I intentionally print the wrong file name and really get an exception. To make sure the file is playing, I sent it to myself and played it on the device.
When I press the button, I don’t hear anything. There are no errors. I do not know what is wrong.
Additional Information iPhone 4 with iOS 5.1 Xcode 4.3.2 Audio is about 700 Kbps, converted to .caf format using afconvert from a large .wav file.
ios iphone audio avaudioplayer core-audio
Aen tan
source share