0
로 음성을 녹음 한 후 나는 AVAudioRecorder과 음성을 녹음하려고 녹음 후 나는 0 바이트와 빈 파일을 가지고 시도가 재생할 때, 나는빈 파일 AVAudioRecorder
2016-12-31 15:28:59.511 FlowerProject[11209:4781594] 15:28:59.511
WARNING: [0x38cb1000] 998: Failure to setup sound, err = -50
내가 사용하려고이 경고를 m4a와 같은 형식 및 0 바이트 크기. 어떤 도움을 주셔서 감사합니다.
는편집 :
- (void)initRecorderWithName:(NSString *)name {
self.recordName = [NSString stringWithFormat:@"%@.wav",name];
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
self.recordName, nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
self.currentSession = [AVAudioSession sharedInstance];
[self.currentSession setCategory:AVAudioSessionCategoryRecord error:nil];
NSMutableDictionary *recordingSettings= [[NSMutableDictionary alloc] init];
[recordingSettings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordingSettings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordingSettings setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordingSettings setValue:[NSNumber numberWithInt: 16] forKey:AVLinearPCMBitDepthKey];
[recordingSettings setValue:[NSNumber numberWithBool: NO] forKey:AVLinearPCMIsBigEndianKey];
[recordingSettings setValue:[NSNumber numberWithBool: NO] forKey:AVLinearPCMIsFloatKey];
[recordingSettings setValue:[NSNumber numberWithInt: AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordingSettings error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
}
: 내가 여기에 오디오를 녹음 및 애니메이션
- (void)commanClickOnPetal:(FlowerObject *)flowerObject andButton:(UIButton *)sender {
if ([[NSUserDefaults standardUserDefaults] boolForKey:flowerObject.imageName] == NO || ![[NSUserDefaults standardUserDefaults] boolForKey:flowerObject.imageName]) {
[self.flowerObject changeRecordedState:YES andKey:flowerObject.imageName];
self.view.userInteractionEnabled = NO;
[self playFirstSound];
[self initRecorderWithName:[NSString stringWithFormat:@"%@sound", flowerObject.imageName]];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self startRecording];
[self.recordIdentifierLabel setHidden:NO];
[UIView animateWithDuration:1.f
delay:0.f
options: UIViewAnimationOptionRepeat | UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse
animations:^{
[self.recordIdentifierLabel setAlpha:0.0f];
} completion:nil];
[UIView transitionWithView:sender duration:29.0f options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowAnimatedContent animations:^{
[sender setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@BW",flowerObject.imageName]] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
self.view.userInteractionEnabled = YES;
[self.recordIdentifierLabel setHidden:YES];
}];
});
} else {
[self playSoundFromPetal:[NSString stringWithFormat:@"%@sound", flowerObject.imageName]];
}
}
을 내 UI를 업데이트하려고 그리고 같은 시간에
레코더 초기화 내 방법입니다 녹음 후 MailCore를 사용하여 이메일로 소리를 보내지 만 파일은 0 바이트입니다. 녹음은 초 30를 계속하고 여기에 [자기 stopRecording]
- (void) startRecording {
if (!recorder.recording) {
AVAudioSession *session = self.currentSession;
[session setActive:YES error:nil];
[recorder record];
self.timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
} else {
[recorder stop];
}
}
- (void) stopRecording {
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
self.dictionaryWithRecords = (NSMutableDictionary *) @{@"URL": recorder.url,
@"Name": self.recordName};
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if ([[DBEmailSender sharedManager] emailAddress] != nil) {
[[DBEmailSender sharedManager] sendMailWithAddress:[[NSUserDefaults standardUserDefaults] objectForKey:@"email"] andCode:nil andFilePath:[self.dictionaryWithRecords objectForKey:@"Name"]];
}
});
}
- (void)updateCountdown {
self.tick += 1;
double seconds = fmod(self.tick, 60.0);
if (seconds == 29) {
self.tick = 0;
seconds = 0;
[self.timer invalidate];
self.timer = nil;
[self stopRecording];
}
}
그리고 메소드를 호출 한 후 내가 버튼을 클릭하여 내 소리를 재생한다 :
이- (void)playSoundFromPetal:(NSString *)soundName {
SystemSoundID mySSID;
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:soundName];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: path], &mySSID);
AudioServicesPlaySystemSound(mySSID);
}
그래서 어떻게 그 개체에서 오디오 세션을 움켜 잡았습니까? – hyd00
@ hyd00 음, 실제로 다른 객체에 대한 세션이 실제로 필요하지 않다는 것을 알았 기 때문에 방금 제거했습니다. 그러나 당신은 또한 시도 할 수 있습니다 : sharedSession = AVAudioSession.sharedInstance하자() 는 { 시도의 sharedSession.setCategory (AVAudioSessionCategoryRecord) (참) sharedSession.setActive을 시도 } 잡기 {} 할 – Goh