2011-08-12 36 views

回答

1

请看看这篇文章:

AVAudioPlayer with external URL to *.m4p

AVAudioPlayer只适用于本地的URL。它必须是一个文件URL(文件://)

Apple's Technical Q&A QA1634

你可以让你的二进制数据,并将其写入到一个文件,然后播放:

NSURL *url = [NSURL URLWithString:@"http://a825.phobos.apple.com/us/r2000/005/Music/d8/a8/d2/mzi.jelhjoev.aac.p.m4p"]; 
NSData *soundData = [NSData dataWithContentsOfURL:url]; 
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
               NSUserDomainMask, YES) objectAtIndex:0] 
               stringByAppendingPathComponent:@"sound.caf"]; 
[soundData writeToFile:filePath atomically:YES]; 
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL 
           fileURLWithPath:filePath] error:NULL]; 
NSLog(@"error %@", error); 
+0

感谢您的回复。 ... – Aarti

相关问题