Iphone 声音在设备中不工作
在我的应用程序中,我为记录而写Iphone 声音在设备中不工作,iphone,audio,Iphone,Audio,在我的应用程序中,我为记录而写 NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString *recordingDirectory = [filePaths objectAtIndex: 0]; NSString *resourcePath = [recordingDirectory stringByApp
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模拟器中一切正常
我先录制,然后停止播放,一切正常
但在我的iPhone设备中没有声音。
任何帮助都将得到极大的感谢我也遇到过类似的问题。然后我将AudioSession类别设置为播放:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
希望这能有所帮助