0

我需要在触摸屏幕时播放文件。

我尝试了以下方法,但没有奏效:

-(IBAction)play;
{
    CFBundleRef mainBundle = CFBundleGetMainBundle();

    CFURLRef soundFileURLRef;

    soundFileURLRef =CFBundleCopyResourceURL(mainBundle, 
    (CFStringRef) @"sound1", CFSTR ("wav"), NULL);

    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
}
4

1 回答 1

1

您是否在窗口或主视图上添加了触摸处理程序?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [yourObject play];
}
于 2012-04-18T17:02:37.817 回答