저는 학생들이 코딩 연습을하고 있습니다.plist (NSArray)에서 노래를 선택하고 AVAudioPlayer를 사용하여 재생 하시겠습니까?
내 앱에 두 개의 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];
}
감사합니다. Damian 님,이 점에 대해 자세히 알아 주셔서 감사합니다. 시도해 보겠습니다 ...이 프로젝트를 통해 몇 가지 길을 걸어 왔습니다. 먼저 MPMusicPlayerController, 다음 AVPlayer, 이제는 AVAudioPlayer ... 힘든 중 하나입니다. 감사! – multi215