Я успешно использовал класс AVAudioPlayer, но после обновления до iOS 5.0 мое приложение iPad вылетает при попытке прослушать то, что я ранее записал.Под iOS 4.3 все хорошо.
Вот код:
NSError * error = NULL;
player =[[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:destinationString]
error:&error];
if(player == NULL)
NSLog( @"error in creating AVAudioPlayer - %@ %@", [error domain], [error localizedDescription] );
[player prepareToPlay];
player.delegate = self;
[player play];
- (NSString*) documentsPath
{
NSArray *searchPaths =
NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* _documentsPath = [searchPaths objectAtIndex: 0];
return _documentsPath;
}
-(void) initRecord
{
audioSession = [[AVAudioSession sharedInstance] retain];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive:YES error:nil];
destinationString = [[self documentsPath]
stringByAppendingPathComponent:@"myRecording.caf"];
NSLog(@"%@", destinationString);
NSURL *destinationURL = [NSURL fileURLWithPath: destinationString];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:destinationURL settings:settings error:&error];
recorder.delegate = self;
}
Приложение вылетает в этой строке:
player =[[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURLfileURLWithPath:destinationString]
error:NULL];
Я уже попробовал NSZombieEnabled, чтодает мне:
0x5368b0 <myRecording = 005BD7D0 | Tag = -1>
*** -[NSPathStore2 length]: message sent to deallocated instance 0x5290e0