2012-07-16 75 views
0

我正在創建一個下載應用程序,我在應用程序內的不同文件夾中有多個音頻文件,我想創建音頻歌曲的播放列表。我不知道從哪裏開始。目前正在使用avaudio播放器。如何創建音頻歌曲的播放列表

回答

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]; 
} 
相關問題