在我的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"];
//以上行工作正常。构建引入并在我的新 View Controller 中显示数据,没有问题。但是,我无法提取字典项随附的音频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词典中选择可变音频文件?
最佳答案
我更改了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]];
关于file - 从Plist播放音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385936/