从Plist播放音频文件
问题描述:
在我的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词典中?
答
我改变了我的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]];