Xcode在prepareToPlay上停止

zer*_*mat 21 xcode objective-c avaudioplayer

使用AVAudioPlayer将声音添加到工作应用程序,它会在prepareToPlay上停止/挂起.请注意,它也会停止/挂起.点击"继续执行程序"几次会使应用程序恢复.只有在模拟器中运行程序时才会出现此问题.

使用Xcode 4.6

代码片段:

ViewController.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController <AVAudioPlayerDelegate>

@end
Run Code Online (Sandbox Code Playgroud)

ViewController.m

#import "ViewController.h"

@interface ViewController ()
{
}

@property (nonatomic, strong) AVAudioPlayer *audioPlayer;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initilizeAudio];
}

- (void)initilizeAudio
{
    NSError *error = nil;
    NSURL *audioURL = [[NSBundle mainBundle] URLForResource:@"Background" withExtension:@"mp3"];

    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error];
    if (error)
    {
        NSLog(@"Error in audioPlayer: %@", [error localizedDescription]);
    }
    else
    {
        [self.audioPlayer setDelegate:self];
        [self.audioPlayer prepareToPlay];
    }
}

@end
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

0 __cxa_throw
21 -[AVAudioPlayer prepareToPlay]
22 -[ViewController viewDidLoad]
.
.
.
Run Code Online (Sandbox Code Playgroud)

zer*_*mat 68

问题是我通常使用设置为"All Exceptions"的断点开发,并且抛出的实际异常是__cxa_throw.这显然是在用于实现AVAudioPlayer的C++库中.通过将断点更改为"所有Objective-C Exceptions",程序运行正常.(这可以通过编辑断点并将Exception字段更改为Objective-C来完成.