我已经进行过搜索,我相信我的问题是非常独特的。我知道当使用AVAudioPlayer时模拟器5.1存在Bug,但这并不是我的问题。我正在iOS 5.1设备上运行。
这是我的头文件:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
-(IBAction)pushBell;
@end
我的实现文件如下:
#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
我在.xib中有一个按钮,用于播放文件。
为了确保我正确引用了音频文件,我特意输入了错误的文件名,确实出现了异常。为了确保文件可以播放,我将其邮件发送给自己,在设备上进行了测试。
当我点击按钮时,听不到任何声音。没有错误提示,我不知道问题出在哪里。
更多信息: iPhone 4,iOS 5.1 Xcode 4.3.2 音频大小约为700kbps,使用afconvert从大型.wav文件转换为.caf格式。