更新到xCode 4.6后AVAudioPlayer崩溃

时间:2013-02-05 14:20:50

标签: ios objective-c xcode avaudioplayer

更新到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

1 个答案:

答案 0 :(得分: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;

希望这有帮助。