Sound does not working in Device
- by diana
In my app i write for record
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *recordingDirectory = [filePaths objectAtIndex: 0];
NSString *resourcePath = [recordingDirectory stringByAppendingString:@"/sound.caf"];
self.soundFileURL = [NSURL fileURLWithPath:resourcePath];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
audioSession.delegate = self;
[audioSession setActive: YES error: nil];
[[AVAudioSession sharedInstance] setCategory : AVAudioSessionCategoryRecorderror: nil];
NSDictionary *recordSettings =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
AVAudioRecorder *newRecorder = [[AVAudioRecorder alloc] initWithURL: soundFileURL settings: recordSettings error: nil];
[recordSettings release];
self.soundRecorder = newRecorder;
[newRecorder release];
soundRecorder.delegate = self;
[soundRecorder prepareToRecord];
[soundRecorder record];
recording = YES;
I write for stop recording
[soundRecorder stop];
recording = NO;
self.soundRecorder = nil;
I write for play
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: self.soundFileURL error: nil];
[fileURL release];
self.player = newPlayer;
[newPlayer release];
[player prepareToPlay];
[player setDelegate: self];
[button setTitle : @"Pause"forState: UIControlStateHighlighted];
[button setTitle : @"Pause"forState: UIControlStateNormal];
[player play];
In iPhone Simulator all ok
I record then stop then play and all work fine.
But in my iPhone device no sound.
Any help will be greatly apprecieated