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