【问题标题】:AVAudioPlayer really strange behaviourAVAudioPlayer 真的很奇怪的行为
【发布时间】:2012-08-23 07:08:54
【问题描述】:

我正在使用 AVAudioPlayer 在应用程序上播放一些 caf 文件,它在所有模拟器(iPhone 和 iPad)和我的 iPhone 上都可以正常工作,但是当我在我的 iPad 上测试它时它不起作用并给出我这个错误:错误域=NSOSStatusErrorDomain Code=-43“操作无法完成。(OSStatus错误-43。)” 奇怪的是,相同的代码在 iPad 上也可以用于另一个应用程序...... iPad更新到IOS版本5.1.1

这是我正在使用的代码:

NSError *error;
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/music.caf", [[NSBundle mainBundle] resourcePath]]]; 

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;

audioPlayer.volume = 0.5;


if (audioPlayer == nil)
    NSLog(@"%@", [error description]);

else
{
    [audioPlayer prepareToPlay];
    [audioPlayer play];
}

在 .h 文件中,我导入了 AVFoundation 和

 AVAudioPlayer *audioPlayer;

AVFoundation.framework 就位

我真的对这件事感到疯狂......任何帮助都将非常感激。 谢谢,马西

【问题讨论】:

    标签: iphone cocoa ipad avaudioplayer


    【解决方案1】:
    NSString* filepath = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"caf"];
    NSURL* url = [NSURL fileURLWithPath:filepath];
    

    【讨论】:

    • 对不起,但这给了我一个错误:由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'*** -[NSURL initFileURLWithPath:]: nil string parameter'
    • 它没有找到您的 .caf 文件,请确保在 xcode 文件检查器中的“目标成员”下检查了您的文件
    • Target Membership 检查成功了……我的代码也可以正常工作……非常感谢!我不明白为什么在我的另一个应用程序中我有相同的代码并且没有检查目标会员资格但它工作正常......无论如何非常感谢您的帮助!我真的很感激和平,马西
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 2011-03-20
    相关资源
    最近更新 更多