0
我正在從xml接收歌曲URL,並將它們作爲二進制數據保存在sqlite中。 現在我想在AVAudioPlayer中播放這些歌曲。如何在AVAudioPlayer中播放歌曲的二進制數據
我該怎麼做到這一點? 這種方法適合在AVAudioPlayer中播放歌曲的二進制數據。
我正在從xml接收歌曲URL,並將它們作爲二進制數據保存在sqlite中。 現在我想在AVAudioPlayer中播放這些歌曲。如何在AVAudioPlayer中播放歌曲的二進制數據
我該怎麼做到這一點? 這種方法適合在AVAudioPlayer中播放歌曲的二進制數據。
請看看這篇文章:
AVAudioPlayer with external URL to *.m4p
AVAudioPlayer只適用於本地的URL。它必須是一個文件URL(文件://)
你可以讓你的二進制數據,並將其寫入到一個文件,然後播放:
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);
感謝您的回覆。 ... – Aarti