更新到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];
答案 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;
希望这有帮助。