我正在使用大约 50 个 AVAudioPlayers,每个都加载一个单独的音频文件。这些文件是固定的并且在应用程序包中。它们由稍后在应用程序中的事件触发。目前我正在硬编码每个播放器实例的创建,如下所示:
//No01
NSURL *no01URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"audio1" ofType:@"aiff"]];
self.no01Player = [[AVAudioPlayer alloc] initWithContentsOfURL:no01URL error:nil];
no01Player.numberOfLoops = 0;
no01Player.volume = 0;
no01Player.delegate = self;
//No02
NSURL *no02URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"audio2" ofType:@"aiff"]];
self.no02Player = [[AVAudioPlayer alloc] initWithContentsOfURL:no02URL error:nil];
no02Player.numberOfLoops = 0;
no02Player.volume = 0;
no02Player.delegate = self;
//No03 and so on...
显然,这是费力且糟糕的编码实践。我希望将文件列表放在 Plist 中,并将它们加载到仅填充上述代码示例的变量中。我想学习如何做到这一点,但从 Plists、数组、字典等加载数据的经验有限。
任何帮助表示赞赏,即使它是指向我相关教程的方向。
谢谢你。