【发布时间】:2011-04-20 19:09:39
【问题描述】:
我是一名正在进行编码练习的学生,我很难过!
我的应用程序中有两个 AVAudioPlayer 实例 - 我可以使用直接路径将歌曲加载到每个播放器中,这没问题。
我希望能够在每个播放器上播放多首歌曲。
这可能吗?如果是这样,我该怎么做?
在我的 plist 中,我将键设置为“One.mp3”作为字符串,并将值设置为文件的路径...(在那个部分猜测)。
感谢您的任何见解。
- (void)viewDidLoad {
[super viewDidLoad];
//multiple song array
NSString *soundsPath = [[NSBundle mainBundle] pathForResource:@"soundslist"
ofType:@"plist"];
soundsList = [[NSArray alloc] initWithContentsOfFile:soundsPath];
NSString* filename = [soundsList objectAtIndex:0];
NSString *path = [[NSBundle mainBundle] pathForResource:filename
ofType:@"mp3"];
AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
self.audioPlayer = newAudio; // automatically retain audio and dealloc old file if new file is loaded
[newAudio release]; // release the audio safely
audioPlayer.delegate = self;
[audioPlayer prepareToPlay];
[audioPlayer setNumberOfLoops:0];
[audioPlayer play];
}
【问题讨论】:
标签: ios audio avaudioplayer