我有一個應用程序,它有兩種聲音: 1.背景聲音,永遠循環直到下一個視圖。 2.發出可以單獨播放或全部播放的剪輯。使用雀歌在iPhone上播放聲音
此前我嘗試過使用AVAudioPlayer,但兩個剪輯之間總是有一個非常小的靜音間隔(我沒有找到任何解決方案,如果有的話,請在回覆中發帖),所以轉向Finch http://github.com/zoul/Finch/tree/master
現在這裏是處理: 我正在使用AVAudioPlayer播放永久的聲音循環,而芬奇播放這些背對背的剪輯。我這樣做:
- (void)viewDidLoad {
[super viewDidLoad];
soundEngine = [[Finch alloc] init];
/***
CLIPPED
***/
}
-(void) playclip:(id) sender {
NSString *fullPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sitar.wav"];
NSLog(@"Song is %@", fullPath);
clip = [[Sound alloc] initWithFile:fullPath];
NSLog(@"Clip Length: %@", clip.length);
NSLog(@"Clip Playing ? : %d", clip.playing);
[clip play];
NSLog(@"Played Clip");
}
這幾乎與在git存儲庫中提供的演示項目代碼相同。但由於某些原因,我得到這個在控制檯上:
Song is /Users/shoaibi/Library/Application Support/iPhone Simulator/User/Applications/17FBA26F-6047-4D56-9E45-ADAFE07B7234/Test.app/sitar.wav
Failed to create OpenAL source, error code a004.
Clip Length: (null)
Clip Playing ? : 0
Played Clip
印在控制檯目錄中的LS顯示,有sitar.wav那裏與正確的權限。可能是什麼問題?可能是我停止使用的背景聲音AVAudioPlayer:
- (void)viewWillAppear:(BOOL)animated {
//Stop the background music before my ears bleed :P
d = [[UIApplication sharedApplication] delegate];
if (d.bg.playing)
{
[d.bg stop];
NSLog(@"Background music stoped");
}
}
是不是釋放聲音資源?
AVAudioPlayer不應該是一個問題,Finch應該沿着AVAudioPlayer就好了。你在模擬器中運行代碼嗎? (文件路徑會提示如此。)模擬器上的OpenAL存在問題,您必須嘗試使用該設備。 – zoul 2009-07-15 04:25:13