2011-07-11 139 views
0

我想循环我的声音文件,我无法找到循环声音文件的参数!我即将把最后站立的头发拉出我的头。它加载罚款....它播放....我只是无法弄清楚如何使其循环的代码。如何循环播放iPhone应用程序的声音?

这里是我的代码:

NSString *eyeBGPath = [[NSBundle mainBundle] pathForResource:@"theeye" ofType:@"caf"]; 
CFURLRef eyeBGURL = (CFURLRef) [NSURL fileURLWithPath:eyeBGPath]; 
AudioServicesCreateSystemSoundID(eyeBGURL, &eyeBackGroundID); 
AudioServicesPlaySystemSound(eyeBackGroundID); 

什么我错在这里做什么?

我发现这一点:

循环 指示当它到达其内容的末尾接收器是否重新播放。默认:NO。

- (BOOL)loops 
Return Value 

YES当接收器在完成时重新开始播放,否则为否。

可用性 适用于Mac OS X v10.5及更高版本。 另请参见 - setLoops: 宣布 NSSound.h

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSound_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSSound/loops

我对如何实现这一困惑。

+0

它真的是一个很大的声音吗? (请不要在您的问题标题中使用全部上限)。 – ceejayoz

+1

对不起,全部。我通常不会把时间花在网络论坛上,所以我不熟悉THE CAPS的事情,有人认为这是大喊大叫。道歉。 – Malin

+0

不用担心,现在你知道了。 :-) – ceejayoz

回答

2

这是为我工作的代码。如果有人需要帮助,请告诉我。苹果开发者论坛上的某个人向我指出了AVFoundation文档。

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/theeye3.caf", [[NSBundle mainBundle] resourcePath]]]; 

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL]; 
audioPlayer.numberOfLoops = -1; 

[audioPlayer play]; 

这里是根据图像数组中的随机数挑出一个声音文件的代码。

NSString *audioWiz = [[NSString alloc]initWithFormat:@"%d.caf", randNum]; 

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:[@"%@/" stringByAppendingString:audioWiz], [[NSBundle mainBundle] resourcePath]]]; 

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL]; 
audioPlayer.numberOfLoops = 0; 
audioPlayer.volume = 0.1; 

[audioPlayer play]; 
0

我认为您正在寻找的答案是here

简短回答,请使用MPMusicPlayerController

+0

NSURL * url = [NSURL fileURLWithPath:[NSString stringWithFormat:@“%@/theeye3.caf”,[[NSBundle mainBundle] resourcePath]]]; \t // NSError * error; \t audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL]; \t audioPlayer.numberOfLoops = -1; [audioPlayer play];此代码有效。 – Malin

相关问题