2011-04-29 2 views

답변

1

나는 마침내 알아 낸 :

NSArray *songs; 
AVAudioPlayer *player; 

- (void)viewDidLoad 
{ 
    [self.player prepareToPlay]; 

    // Point to Document directory 
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
    NSError *error = nil; 
    NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error]; 

    if (array == nil) { 
    // Handle the error 
    } 
    self.songs = array; 
    //[array release]; 

    //self.title = @"Song List"; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *applicationDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; 
    NSString *filePath = [applicationDocumentsDirectory stringByAppendingPathComponent: [songs objectAtIndex:indexPath.row]]; 
    NSURL *url = [NSURL fileURLWithPath:filePath]; 

    player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil]; 

    [player play]; 
} 
관련 문제