Надеюсь, что я задаю этот вопрос правильно сейчас, я спросил здесь раньше и немного опустился, но надеюсь, что сейчас будет очень точно. Я уже не нашел здесь рабочего ответа, только iOS-решения, но не для OSX/Mac-приложенийAVAudioRecorder на Mac: операция не может быть завершена
Я пытаюсь получить работу AVAudioRecorder. Это не IOS приложений, поэтому я не могу использовать UIKit, AVAudioSession и т.д.
//
// AppDelegate.m
// NeuerAudioShit
//
// Created by dominik said on 10/12/2015.
// Copyright © 2015 dominik said. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate()
@property (weak) IBOutlet NSButton *playButton;
@property (weak) IBOutlet NSButton *button;
@property (weak) IBOutlet NSWindow *window;
@property (strong) AVAudioRecorder* audioRecorder;
@property (strong) AVAudioPlayer* player;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (IBAction)playRecording:(id)sender {
NSURL *url = [NSURL URLWithString:@"/Users/dominik/Coding/file.mp3"];
_player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
[_player setVolume: 1.0];
[_player play];
}
- (IBAction)buttonPressed:(id)sender {
NSLog(@"Hello World");
NSURL *url = [NSURL URLWithString:@"/Users/dominik/Coding/file.mp3"];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt: kAudioFormatAppleIMA4],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
_audioRecorder = [[AVAudioRecorder alloc]
initWithURL:url
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
}
else {
NSLog(@"jo");
}
[_audioRecorder setDelegate:self];
if ([_audioRecorder prepareToRecord] == YES){
[_audioRecorder record];
}else {
int errorCode = CFSwapInt32HostToBig ([error code]);
NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);
}
}
@end
Это дает мне следующий вывод в журнал, когда я называю функцию записи:
2015-12-10 04:21:39.306 NeuerAudioShit[29099:2206838] Hello World
2015-12-10 04:21:39.699 NeuerAudioShit[29099:2206838] error: The operation couldn’t be completed. (OSStatus error 1718449215.)
2015-12-10 04:21:39.699 NeuerAudioShit[29099:2206838] Error: The operation couldn’t be completed. (OSStatus error 1718449215.) [fmt?])