【发布时间】:2011-06-06 04:01:36
【问题描述】:
我正在装有 iOS 4.2 的 3GS iPhone 上测试我的应用
我正在使用以下代码在我的 IBAction 中播放声音。它在模拟器(iPad 和 iPhone)中完美运行 - 我听到了声音。
NSString *pathToMusicFile1 = [[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"mp3"];
NSError *error;
alarmSound = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile1] error:&error];
NSLog(@"Song1 Loaded");
if (alarmSound == nil) {
NSLog(@"Error playing sound");
} else {
alarmSound.numberOfLoops = 20;
alarmSound.volume = 1.0;
[alarmSound play];
}
我已经正确声明了所有内容(标题和框架等),因为我可以在模拟器中听到声音。
我还检查了我的手机没有处于静音模式!!我从通用 iphone GUI 听到其他声音。 (来自日期选择器的示例)。
我还清理了所有目标并删除了要重新安装的应用程序。
任何想法有什么问题吗?!
【问题讨论】:
标签: iphone iphone-sdk-3.0 ios4 avaudioplayer