我想通过使用循环播放多个文件。
我写的代码如下..
请帮我。!!
如何在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