Xcode在prepareToPlay上停止 [英] Xcode stops on prepareToPlay

查看:118
本文介绍了Xcode在prepareToPlay上停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AVAudioPlayer向运行中的应用程序添加声音,它会停止/挂在prepareToPlay上.请注意,它也会停止/挂起播放.多次单击继续执行程序"会使应用程序恢复.仅当在模拟器中运行程序时,才会出现此问题.

Using AVAudioPlayer to add sound to a working application, it stops / hangs on prepareToPlay. Note it also stops / hangs on play. Hitting "Continue program execution" several times makes the application resume. This problem only occurs when running the program in the simulator.

使用Xcode 4.6

Using Xcode 4.6

代码段:

ViewController.h

ViewController.h

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

@interface ViewController : UIViewController <AVAudioPlayerDelegate>

@end

ViewController.m

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异常",程序可以正常运行. (这可以通过编辑断点并将Exception字段更改为Objective-C来完成.

The problem was I normally develop with a breakpoint set to "All Exceptions", and the actual exception thrown was __cxa_throw. Which apparently turns out to be in C++ libraries that are used to implement AVAudioPlayer. By changing the breakpoint to "All Objective-C Exceptions" the program ran fine. (This can be done by editing the breakpoint and changing the Exception field to Objective-C.

这篇关于Xcode在prepareToPlay上停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆