objective-c – Xcode在prepareToPlay上停止

前端之家收集整理的这篇文章主要介绍了objective-c – Xcode在prepareToPlay上停止前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用AVAudioPlayer向工作的应用程序添加声音,它会停止/挂起在prepareToPlay上。注意它也停止/挂起播放。几次打“继续程序执行”使应用程序恢复。只有在模拟器中运行程序时才会出现此问题。

使用Xcode 4.6

代码段:

ViewController.h

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

@interface ViewController : UIViewController <AVAudioPlayerDelegate>

@end

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

堆栈跟踪

0 __cxa_throw
21 -[AVAudioPlayer prepareToPlay]
22 -[ViewController viewDidLoad]
.
.
.

解决方法

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

猜你在找的Xcode相关文章