iOS AVAudioPlayer播放音频时,已经将音频下载了本地,怎么还出现下面的错误啊
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS AVAudioPlayer播放音频时,已经将音频下载了本地,怎么还出现下面的错误啊相关的知识,希望对你有一定的参考价值。
Error Domain=NSOSStatusErrorDomain Code=1954115647 "The operation couldn’t be completed. (OSStatus error 1954115647.)"
这是我的代码:
//将数据保存到本地指定位置
NSString *urlStr = [self.audioArray objectAtIndex:sender.tag];
NSLog(@"urlStr === %@",urlStr);
NSURL *url = [[NSURL alloc]initWithString:urlStr];
NSData * audioData = [NSData dataWithContentsOfURL:url];
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.arm", docDirPath , @"temp"];
[audioData writeToFile:filePath atomically:YES];
//播放本地音乐
NSError *error = nil;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if (player == nil)
NSLog(@"error === %@",[error description]);
player.delegate = self;
[player play];
NSData *audioData = [NSData dataWithContentsOfURL:someURL];
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , fileName];
[audioData writeToFile:filePath atomically:YES];
NSError *error;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if (player == nil)
NSLog(@"AudioPlayer did not load properly: %@", [error description]);
else
[player play];
追问
谢谢你的答案,但是我这边还是报错:
Error Domain=NSOSStatusErrorDomain Code=1954115647 "The operation couldn’t be completed. (OSStatus error 1954115647.)"
真是够灰心的,就简单的十几行代码,却怎么整,都是错
以上是关于iOS AVAudioPlayer播放音频时,已经将音频下载了本地,怎么还出现下面的错误啊的主要内容,如果未能解决你的问题,请参考以下文章