【问题标题】:AVAudioSession setCategory errorAVAudioSession setCategory 错误
【发布时间】:2013-07-26 19:47:14
【问题描述】:

试试这个:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

if (error) {
    NSLog(@"Error setting category: %@", [error description]);
}

返回错误“错误设置类别:UIView”,但不确定如何解决此问题。不完全确定它在告诉我什么。

请帮忙!

编辑

音频播放:

NSURL *audioFileURL = [[NSBundle mainBundle] URLForResource:@"DemoSong" withExtension:@"m4a"];
NSError *error;

self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];

if (error) {
    NSLog(@"%@", [error localizedDescription]);
}

[_audioPlayer setNumberOfLoops:-1];
[_audioPlayer setMeteringEnabled:YES];
[_visualizer setAudioPlayer:_audioPlayer];

[_audioPlayer prepareToPlay];
[_audioPlayer play];
NSLog(@"play audio");

【问题讨论】:

    标签: ios objective-c audio avaudiosession


    【解决方案1】:

    您应该检查[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error] 的返回值,如果成功则返回YES,如果失败则返回NO

    如果setCategory:error: 的返回值为NO,则只查看error 变量。

    【讨论】:

    • 检查返回值给了我一个真实的结果。音频仍然没有播放。
    • 你能用实际音频播放的代码编辑你的问题吗?
    • @Lagoo87 在你做self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];之后尝试检查_audioPlayer == nil
    • 是的,它说它出于某种原因是空的。
    • 啊,我明白了 - 文件没有复制到捆绑资源中。谢谢你帮我找到这个:)
    【解决方案2】:

    尝试将您的代码更改为:

    NSError * error = nil;
    BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
    if(NO == success)
    {
        NSLog(@"Error setting category: %@", [error localizedDescription])
    }
    

    看看你是否得到了更具描述性和帮助的东西。

    【讨论】:

      猜你喜欢
      • 2016-11-10
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 2016-09-27
      • 2016-12-04
      • 1970-01-01
      相关资源
      最近更新 更多