开发者

how to play binarydata of song in AVAudioPlayer

I'm receiving songs url from xml and saving them in sqlite as binary data. Now I want to play those so开发者_如何学Cngs in AVAudioPlayer.

How would I achieve this? Is this method is right for playing binarydata of song in AVAudioPlayer.?


Please have a look at this post:

AVAudioPlayer with external URL to *.m4p

AVAudioPlayer only works with local URL's. It must be a File URL (file://)

See Apple's Technical Q&A QA1634

You could get your binary data and write it to a file and then play it:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜