Sound does not working in Device

Posted by diana on Stack Overflow See other posts from Stack Overflow or by diana
Published on 2009-08-06T04:28:48Z Indexed on 2010/05/01 21:37 UTC
Read the original article Hit count: 335

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about iphone

Related posts about sound