2011-08-12 35 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

相關問題