【发布时间】:2011-06-01 02:23:01
【问题描述】:
我正在尝试制作一个带有一些按钮的小型 iPhone 应用程序来播放 WAV 声音。 我的按钮可以工作,但延迟时间很短(~ 0.5 秒)。
这是我的 .m 文件:
#import "buttonSoundViewController.h"
@implementation buttonSoundViewController
//@synthesize player;
-(IBAction) playSoundA:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"wav"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
-(IBAction) playSoundB:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"b" ofType:@"wav"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
[player release];
}
-(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
}
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player {
}
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player {
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[audioPlayer release];
[super dealloc];
}
@end
如何避免播放不同声音之间的延迟?
【问题讨论】:
-
WAV 文件大吗?尝试使用较小的文件类型,看看它是否会缩短加载时间
-
@Mark No 我的 WAV 文件很轻(1 秒,~ 500 Kb)。
标签: iphone objective-c cocoa-touch audio latency