1
工作在我的應用我寫備案聲音並非在設備
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;
我寫停止錄製
[soundRecorder stop];
recording = NO;
self.soundRecorder = nil;
我寫的播放按鈕
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];
在iPhone模擬器一切正常
我記錄然後st然後玩,一切正常。
但在我的iPhone設備上沒有聲音。 任何幫助將大大惠及