1
我是一名正在编程练习的学生,我很难过!从plist(NSArray)挑选歌曲并使用AVAudioPlayer播放?
我的应用程序中有两个AVAudioPlayer实例 - 我可以使用直接路径将歌曲加载到每个播放器中都没有问题。
我想要做的就是播放每个播放器中阵列中的多首歌曲。
这可能吗?如果是的话,我会如何去做这件事?
在我的plist中,我将键设置为“One.mp3”作为字符串,并将值作为文件的路径...(正在猜测该部分)。
感谢您的任何见解。
- (void)viewDidLoad {
[super viewDidLoad];
//multiple song array
NSString *soundsPath = [[NSBundle mainBundle] pathForResource:@"soundslist"
ofType:@"plist"];
soundsList = [[NSArray alloc] initWithContentsOfFile:soundsPath];
NSString* filename = [soundsList objectAtIndex:0];
NSString *path = [[NSBundle mainBundle] pathForResource:filename
ofType:@"mp3"];
AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
self.audioPlayer = newAudio; // automatically retain audio and dealloc old file if new file is loaded
[newAudio release]; // release the audio safely
audioPlayer.delegate = self;
[audioPlayer prepareToPlay];
[audioPlayer setNumberOfLoops:0];
[audioPlayer play];
}
谢谢Damian,感谢您对此的见解,我会试一试......我已经在这个项目中走过了几条道路。首先是MPMusicPlayerController,然后是AVPlayer,现在是AVAudioPlayer ......非常强大。谢谢! – multi215 2011-04-20 19:56:34