触摸屏幕时我需要播放文件。
我尝试了以下方法,但它无效:
-(IBAction)play;
{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle,
(CFStringRef) @"sound1", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
答案 0 :(得分:1)
您是否在窗口或主视图上添加了触控处理程序?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
[yourObject play];
}