AVAudioPlayer与外部URL为* .m4p [英] AVAudioPlayer with external URL to *.m4p

查看:344
本文介绍了AVAudioPlayer与外部URL为* .m4p的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题如下。我得到这个code,我想一个腐败NSURL自从AVAudioPlayer初始化后为零:

 的NSString * dummyURLString = @http://a825.phobos.apple.com/us/r2000/005/Music/d8/a8/d2/mzi.jelhjoev.aac。 p.m4p;
NSError *错误;
NSURL * URL = [NSURL URLWithString:dummyURLString];
AVAudioPlayer *玩家= [[AVAudioPlayer页头] initWithContentsOfURL:URL错误:&放大器;错误]
[播放器播放];

任何建议是怎么回事错在这里?

&该放大器;错误表明这一点:

 错误域= NSOSStatusErrorDomain code = -43操作无法完成。(OSStatus错误-43)。


解决方案

我尝试这样做第一,但遇到错误2003334207:

 的NSData * soundData = [NSData的dataWithContentsOfURL:URL]
AVAudioPlayer *玩家= [[AVAudioPlayer页头] initWithData:soundData错误:&放大器;错误]

似乎AVAudioPlayer真正想要的文件。所以,我把数据写入文件第一:

  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的文件路径= [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,是)objectAtIndex:0]
stringByAppendingPathComponent:@sound.caf];
[soundData将writeToFile:文件路径原子:YES];
玩家= [[AVAudioPlayer页头] initWithContentsOfURL:[NSURL
fileURLWithPath:文件路径]错误:NULL];
的NSLog(@错误%@,错误);

My Problem is the following. I got this code and i guess a corrupt NSURL since the AVAudioPlayer is nil after initializing:

NSString *dummyURLString = @"http://a825.phobos.apple.com/us/r2000/005/Music/d8/a8/d2/mzi.jelhjoev.aac.p.m4p";
NSError *error;
NSURL *url = [NSURL URLWithString:dummyURLString]; 
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[player play];

Any suggestions what is going wrong here?

The &error shows this:

Error Domain=NSOSStatusErrorDomain Code=-43 "Operation could not be completed. (OSStatus error -43.)"

解决方案

I tried this first but got error 2003334207:

NSData *soundData = [NSData dataWithContentsOfURL:URL];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:soundData error:&error];

Seems that AVAudioPlayer really wants a file. So I put the data into a file first:

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);

这篇关于AVAudioPlayer与外部URL为* .m4p的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆