0

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

4

1 回答 1

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];
}
于 2012-07-16T09:29:49.763 回答