我搜索过,我相信我的问题非常独特.我知道使用AVAudioPlayer时的模拟器5.1错误,这不是我的问题.我在iOS 5.1设备上运行.
这是我的头文件:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
-(IBAction)pushBell;
@end
Run Code Online (Sandbox Code Playgroud)
和我的实施文件:
#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
Run Code Online (Sandbox Code Playgroud)
我的.xib中有一个按钮来播放该文件.
为了确保我正确引用了我的音频文件,我故意输入了错误的文件名,实际上我得到了一个例外.为了确保文件可播放,我将其邮寄给自己并在设备上播放.
当我点击按钮时,我什么都没听到.没有错误.我不知道出了什么问题.
更多信息 iPhone 4与iOS 5.1 Xcode 4.3.2音频大约700kbps转换为.caf格式使用afconvert从一个大的.wav文件.