我想通過使用循環播放多個文件。
我寫的代碼如下..
請幫我。!!
如何在AVAudioPlayer中循環播放多個音頻文件?
soundList = [[NSArray alloc] initWithObjects:@"mySong1.mp3",@"mySong2.mp3",@"mySong3.mp3",@"mySong4.mp3",@"mySong5.mp3",@"mySong6.mp3",@"mySong7.mp3",@"mySong8.mp3",@"mySong9.mp3", nil];
for (i=0; i<=([soundList count] - 1);) {
while(i<[soundList count]){
NSLog(@"File is : %@",[soundList objectAtIndex:i]);
mediaPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:[soundList objectAtIndex:i] ofType:nil]] error:&error];
[mediaPlayer setDelegate:self];
self.lblCurrentSongName.text = [soundList objectAtIndex:i];
[mediaPlayer prepareToPlay];
i++;
}
}
請給我建議。!!
非常感謝你[guenis(http://stackoverflow.com/users/837244/guenis) –
HI [guenis(HTTP:// stackoverflow.com/users/837244/guenis)..我嘗試了它,它是成功的,但它不會自動播放下一首歌曲。我應該爲此採取行動。請幫助我自動播放所有歌曲。再次感謝.. –
我已編輯的代碼,通知[MediaPlayer的setDelegate:自我]現在是裏面playCurrentSong。事實證明,當你分配你需要設置代理再次在vc新avaudioplayer,否則audioPlayerDidFinishPlaying方法開不被調用,它不會自動播放下一首歌曲,我的錯誤 – guenis