我想问一下当按下“开始”按钮时我应该写下什么来播放功能e1play。我想玩cat.wav声音。怎么称呼它。当我制作例如[MainView e1play]时,它会向我显示一些错误。请帮忙。
这是我的h档案。
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface MainView : UIView {
AVAudioPlayer *avPlayer1;
}
- (void)e1play:(id)sender;
- (IBAction)start:(id)sender;
和m档
@implementation MainView
- (void)e1play:(id)sender{ //function to play sound of the cat
NSString *path = [[NSBundle mainBundle] pathForResource:@"cat" ofType:@"wav"];
avPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[avPlayer1 play];
}
- (IBAction)start:(id)sender{ //button to lunch function e1play
//??????
}
@end
答案 0 :(得分:1)
如果你需要像播放声音那样简单的东西,你可能应该这样:
AudioServicesCreateSystemSoundID
AudioServicesPlaySystemSound
AudioServicesDisposeSystemSoundID
...您只需为每个想要播放的声音存储SystemSoundID。