问题
我正在尝试在iOS应用中播放一小段(4秒)音频剪辑。
我正在Snow Leopard 10.6.8之上的VMWare上的Lion VM实例10.7.2中运行。
我尝试过的
代码
// Usage from class
-(void)loadRunningView {
JGTimerRunningViewController *runningViewController = [[JGTimerRunningViewController alloc] initWithNibName:@"JGRunningViewController" bundle:nil];
[runningViewController loadAlertSoundWithFilename:@"DigitalAlarm1"];
}
@interface JGTimerRunningViewController : UIViewController {
IBOutlet UILabel *timeLabel;
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
}
@implementation JGTimerRunningViewController
-(void)loadAlertSoundWithFilename:(NSString *)alertSoundFilename_ {
// Get the main bundle for the app
CFBundleRef mainBundle = CFBundleGetMainBundle ();
CFStringRef filename = (CFStringRef)alertSoundFilename_;
soundFileURLRef = CFBundleCopyResourceURL (mainBundle, filename, CFSTR ("aiff"), NULL);
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
}
..
-(IBAction)playSound:(id)sender {
AudioServicesPlaySystemSound (soundFileObject);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
-(void)showRedCard {
[[self view] setBackgroundColor:[UIColor redColor]];
[self playSound:self];
}
...
- (void)dealloc {
CFRelease(soundFileURLRef);
AudioServicesDisposeSystemSoundID(soundFileObject);
[timeLabel release];
[super dealloc];
}
@end
最佳答案
您是否检查过文件大小写与文件名匹配的大小写,即“DigitalAlarm1”而不是“Digitalalarm1”,等等。模拟器不区分大小写,但设备区分大小写。
关于iphone - 系统音频播放使运行iOS 4.2.1的iPhone保持静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8790260/