0

在我的 Controller.h 文件中...我列出了我正在使用的 NSDictionary 以及要提取的项目。但我在识别录音变量时遇到问题......

@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"];     

//以上行工作正常。构建拉入并在我的新视图控制器中显示数据,没有问题。但是,我无法提取字典项附带的音频 m4a 文件。使用下面的代码,我可以播放一个特定的音频文件...但是如何更改下面的代码以拉入当前表级别的 plist 字典中列出的音频文件?仅供参考,音频文件与对象键一起列出:“录音”类型:“字符串”和变量值,如:“buzz.4ma”

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

//如何让pathForResource选择plist字典中的可变音频文件?

4

1 回答 1

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]];
于 2012-07-09T12:20:23.827 回答