2
好這部作品嘗試在iPhone上播放聲音
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
// Load the sounds
NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Begin Drawing" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &_boomSoundIDs[0]);
soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Middle Drawing" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &_boomSoundIDs[1]);
soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"End Drawing" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &_boomSoundIDs[2]);
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touches count] == 1)
{
AudioServicesPlaySystemSound(_boomSoundIDs[0]);
}
但是,這就是我想解決
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
AudioServicesPlaySystemSound(_boomSoundIDs[1]);
}
它只是起到這樣持續的聲音不會玩一路過關斬將,但每次用戶移動他們的手指開始時,我想要的是實際上一直播放,然後再次循環播放
好的我修復了格式化,對此抱歉。但我不知道如何檢查聲音是否在播放。 – Jaba 2009-12-08 18:59:33
如果您查看(AudioServicesPlaySystemSound參考)[http://developer.apple.com/iphone/library/documentation/AudioToolbox/Reference/SystemSoundServicesReference/Reference/reference.html#//apple_ref/c/func/AudioServicesPlaySystemSound]你會看到你可以註冊一個回調(通過AudioServicesAddSystemSoundCompletion)。這有幫助嗎? – EightyEight 2009-12-09 05:38:26
那麼我已經看過,但我只是不明白添加和刪除回調especialy這一過程。如果你可以請給我一個關於這個過程的探索和/或他們在這個過程中做什麼,那會很棒。我求你。 – Jaba 2009-12-09 14:23:25