2012-07-08 73 views
0

在我的Controller.h文件中...我列出了我使用的NSDictionary以及要拉出的項目。但我有識別錄音變量的一個問題...從Plist播放音頻文件

@property (nonatomic, retain) NSDictionary *dataForCurrentLevel; 
@property (nonatomic, retain) IBOutlet UILabel *Name; 
@property (nonatomic, retain) IBOutlet UILabel *Author; 
@property (nonatomic, retain) IBOutlet UILabel *Time; 
@property (nonatomic, retain) NSString *Recording; 

在我Controller.m或者文件....

- (void)viewDidLoad 
{  

// Configure the user interface by extracting the data from the dictionary 
    Name.text = [dataForCurrentLevel valueForKey:@"Name"]; 
    Author.text = [dataForCurrentLevel valueForKey:@"Author"]; 
    Time.text = [dataForCurrentLevel valueForKey:@"Time"];  

//上面的紋路工作AOK。該版本引入並顯示我的新視圖控制器中的數據沒有問題。但是,我無法拉入伴隨字典項目的音頻m4a文件。使用下面的代碼,我可以播放一個特定的音頻文件...但是,如何更改下面的代碼,以便在當前表級別下拉列表中列出的音頻文件?僅供參考,音頻文件列有對象鍵:「錄音」類型:「字符串」等變量值:「buzz.4ma」

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"buzz" ofType:@"m4a"]]; 
self.myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error:nil]; 

//我怎麼pathForResource選擇可變音頻文件在plist詞典中?

回答

1

我改變了我的plist字典,發現解決方案是: NSDictionary * dict = [NSDictionary dictionaryWithContentsOfFile:plistPath]; dict = [dict objectForKey:@「Root」];

for (int i = 0; i < numberOfSongs; i++){ 

    NSDictionary *songInfo = [dict objectForKey:[NSString stringWithFormat:@"Item%d",i]];