file - 从Plist播放音频文件

标签 file audio dictionary plist

在我的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/

相关文章:

c - 释放从 C 函数返回的内存

dictionary - 不变字典

python - 将列表转换为字典

android - 从其他 Android 应用程序请求记录焦点

sockets - 使用NAudio播放来自android设备的音频字节流

video - FFMpeg 将 AVI 转换为 MP4 - 音频/视频不同步

c++ - 如何在 c++11/c++14 中定义一个以枚举为键、以整数为值的映射?

javascript - 读取文件并将其存储在javascript中的数组中

ruby - 如何选择具有特定扩展名的文件? ruby

android - 从 parseObject 获取文件