當用戶正在主動運行我的應用程序時,我想運行輕音樂(不停止)。當用戶退出我的應用程序時,音樂將自動停止。我嘗試了下面的代碼來執行連續的音樂播放(即,在循環中播放音樂)。但它並不實際循環;一旦音樂完成,它結束音樂。當我的iPhone應用程序正在運行時,如何在後臺播放連續音樂?
- (void) PlayLoopMusic {
NSString* path;
NSURL* url;
path = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
[player prepareToPlay];
[player setVolume: 0.030];
[player setDelegate: self];
// Start playing it while starting the game ...
[player play];
}
有人可以建議實現循環,連續音樂的方法嗎?
請有一種方法來關閉音樂。大多數人會因爲播放音樂而無法關閉的應用程序(尤其是網頁)而非常惱火。 – rmeador 2009-11-24 22:08:40
Ofcourse,我確實...感謝您的建議。 – Getsy 2009-11-25 05:39:42