AVAudioPlayer播放在線音頻文件
一:原里:
AVAudioPlayer是不支持播放在線音頻的,但是AVAudioPlayer有一個 initWithData的方法;我們可以把在線音頻轉換為NSdata;
然后播放
二:如代碼:
NSData *soundData = [sharedAppSettingsController getSoundUrl:defaultDictionaryID uri:soundUrl];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithData:soundData error:&error];
audioPlayer.numberOfLoops = 0;
if (error) {
NSLog(@"Error: %@",[error description]);
}
else {
audioPlayer.delegate = self;
[audioPlayer play];
}
參考 :http://stackoverflow.com/questions/3767998/iphone-avaudioplayer-app-freeze-on-first-play
