如何创建音频歌曲的播放列表

时间:2012-07-16 08:25:52

标签: iphone objective-c

我正在创建一个下载应用程序,其中我在应用程序内的不同文件夹中有多个音频文件,我想创建音频歌曲的播放列表。我不知道从哪里开始。目前正在使用avaudio播放器。

1 个答案:

答案 0 :(得分:0)

试试这个

NSArray *array = [[NSMutableArray alloc]init ];
[array insertObject: [[NSString alloc] initWithFormat:[[NSBundle mainBundle] pathForResource:@"firstTrack" ofType:@"mp3"]] atIndex:0];
[array insertObject:[[NSString alloc] initWithFormat: [[NSBundle mainBundle] pathForResource:@"secondTrack" ofType:@"mp3"]] atIndex:1];
[array insertObject:[[NSString alloc] initWithFormat: [[NSBundle mainBundle] pathForResource:@"thirdTrack" ofType:@"mp3"]] atIndex:2];
[array insertObject:[[NSString alloc] initWithFormat: [[NSBundle mainBundle] pathForResource:@"forthTrack" ofType:@"mp3"]] atIndex:3];

然后在播放器中:

    path = [array objectAtIndex:currentTrack];

或使用此:

path=[[NSBundle mainBundle] pathForResource:@"sounds" ofType:@"plist"];
dict=[NSDictionary dictionaryWithContentsOfFile:path];

animalaudio=[dict valueForKey:@"audio"];
  audiolist=[animalaudio objectAtIndex:currentsound];
NSLog(@"audiolist:%@",audiolist);
url=[NSURL fileURLWithPath:audiolist];
NSLog(@"url:%@",url);
 audioplayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
NSLog(@"audioplayer:%@",audioplayer);
 if( audioplayer == nil ){

    NSLog(@"Failed with reason: %@", [error localizedDescription]);
}
else{
    [audioplayer play];
}