【问题标题】:how to solve run time error of The operation couldn’t be completed. (OSStatus error -43.)?如何解决无法完成操作的运行时错误。 (OSStatus 错误 -43。)?
【发布时间】:2012-07-16 09:09:26
【问题描述】:

我是 iPhone 的初学者。我想播放音频。为此,我使用了 AVAudioPlayer.. 但该对象返回空值.. 并且还给出了操作无法完成的运行时错误。 (OSStatus 错误 -43。)

这是我使用的代码

-(IBAction)sound
{
   NSError *error;
   int currentsound;
    path=[[NSBundle mainBundle] pathForResource:@"Animalfile" ofType:@"plist"];
    dict=[NSDictionary dictionaryWithContentsOfFile:path];

    animalaudio=[dict valueForKey:@"audio"];
    NSLog(@"print:%@",dict);
    NSLog(@"printanimal%@",animalaudio);
    audiolist=[animalaudio objectAtIndex:currentsound];
    NSLog(@"audiolist:%@",audiolist);
    url=[NSURL fileURLWithPath:audiolist];
    NSLog(@"url:%@",url);
     audioplayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
    NSLog(@"audioplayer:%@",audioplayer);
     if( audioplayer == nil ){

        NSLog(@"Failed with reason: %@", [error localizedDescription]);
    }
    else{
        [audioplayer play];
    }
  }

在那个url中也返回了mp3文件,但是为什么url不传入AVAudioPlayer,因为audioplayer返回null但不返回mp3 file.so,我在AVAudioPlayer中写了哪些代码?给出任何建议和源代码....

【问题讨论】:

    标签: objective-c


    【解决方案1】:
    path=[[NSBundle mainBundle] pathForResource:@"Animalfile" ofType:@"plist"];
    

    路径必须是单个文件而不是 plist

    尝试给路径一个值

    例子:

    path = [[NSString alloc] initWithFormat:[[NSBundle mainBundle] pathForResource:@"firstTrack" ofType:@"mp3"]]
    

    【讨论】:

      【解决方案2】:

      -43 是文件未找到错误 检查您的 plist 中的相对文件路径是否可以从工作目录中找到。 或者更好的是,使用 NSBundle 的众多资源查找方法之一直接查找您的声音文件,然后您将获得一个现有的绝对路径。

      【讨论】:

        猜你喜欢
        • 2020-07-29
        • 1970-01-01
        • 2018-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-10
        • 2019-02-18
        相关资源
        最近更新 更多