0

更新到 xCode 4.6 后,我的音频播放器崩溃且没有错误日志。我无法记录错误,因为它在播放时崩溃。我在调试器上没有收到任何消息,只有一个线程/断点。有人有什么想法吗?

NSError *error;
NSString *stringPath1 = [[NSBundle mainBundle] pathForResource:@"beep" ofType:@"mp3"];
NSURL *url1 = [NSURL fileURLWithPath:stringPath1];
playerForRecording = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:&error];
[playerForRecording setDelegate:self];
[playerForRecording play];

http://i1107.photobucket.com/albums/h385/snksnk1/stack%20overflow/ScreenShot2013-02-05at54421PM_zps72842a8f.png

4

1 回答 1

0

我正在使用相同的编译器,这对我有用:

NSError *error;
NSString *stringPath1 = [[NSBundle mainBundle] pathForResource:@"beep" ofType:@"mp3"];
NSURL *url1 = [NSURL fileURLWithPath:stringPath1];
NSAssert(url1, @"URL is valid.");
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:&error];
if(!self.player)
{
    NSLog(@"Error creating player: %@", error);
}
[self.player play];

当然,在 .h 中,有以下几行:

#import <AVFoundation/AVFoundation.h>
@interface myProgramViewController : UIViewController<AVAudioPlayerDelegate>

...

@property (nonatomic, strong) AVAudioPlayer* player;

在.m中,对应的:

@synthesize player = mPlayer;

希望这可以帮助。

于 2013-02-05T15:05:36.313 回答