2012-04-18 70 views
0

我需要在触摸屏幕时播放文件。如何播放声音文件“OnTouch”

我曾尝试以下,但它没有工作:

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

    CFURLRef soundFileURLRef; 

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

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

回答

1

你你的窗口或主视图上增添了一抹处理?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [super touchesBegan:touches withEvent:event]; 
    [yourObject play]; 
}