【发布时间】:2015-03-31 11:41:24
【问题描述】:
这是我的代码,首先我调用 mp3 url 来下载音频数据。然后我将该数据保存在本地目录中,之后我正在从本地文件路径播放音频,但它不起作用AVAudioPlayer 抛出错误。我也尝试了其他一些方法,但没有人适合我。
在模拟器上相同的代码工作正常。
并且音频网址在浏览器中播放起来就像一个魅力。
NSURL *urlll=[NSURL URLWithString:@"www.xyz.audio.mp3"];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:urlll] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *responce,NSData* data,NSError * error) {
if (error == nil)
{
indicator.hidden=YES;
[indicator stopAnimating];
if (data)
{
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , @"Audio"];
[data writeToFile:filePath atomically:YES];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
AudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
AudioPlayer.delegate=self;
[AudioPlayer prepareToPlay];
if (AudioPlayer == nil) {
NSLog(@"AudioPlayer did not load properly: %@", [error description]);
} else {
[AudioPlayer play];
}
}
}
}];
但我遇到了这些错误:Error Domain=NSOSStatusErrorDomain Code=1685348671 "The operation couldn't be completed. (OSStatus error 1685348671.)
请帮帮我:(。
【问题讨论】:
-
这个代码在你的 viewDidLoad 中吗?
-
否,此代码是从 tableview 调用并选择。
标签: ios objective-c avaudioplayer