Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标C-录制音频流_Objective C_Avplayer - Fatal编程技术网

Objective c 目标C-录制音频流

Objective c 目标C-录制音频流,objective-c,avplayer,Objective C,Avplayer,我正在寻找一种解决方案,将音频流录制到文件中。我可以播放音频,但我正在努力找出如何录制/保存正在播放的内容 如果能朝着正确的方向轻推一下,我们将不胜感激 迄今为止的玩家代码: @interface ViewControllerPlayer () @end @implementation ViewControllerPlayer @synthesize receivedStreamReferenceNumber; - (void)convertData:(NSData *) data {

我正在寻找一种解决方案,将音频流录制到文件中。我可以播放音频,但我正在努力找出如何录制/保存正在播放的内容

如果能朝着正确的方向轻推一下,我们将不胜感激

迄今为止的玩家代码:

@interface ViewControllerPlayer ()

@end

@implementation ViewControllerPlayer

@synthesize receivedStreamReferenceNumber;

- (void)convertData:(NSData *) data {
    NSString *urlString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSURL *url = [[NSURL alloc] initWithString:urlString];
    [self loadPlayer:url];
}

- (void) loadPlayer:(NSURL *) url {
    audioPlayer = [AVPlayer playerWithURL:url];
    [audioPlayer play];
}

- (void) start {
    NSLog(@"%@", receivedStreamReferenceNumber);
    NSString *urlHalf = @"http://getstreamurl.php?KeyRef=";
    NSMutableString *mutableUrlString = [NSMutableString stringWithFormat:@"%@%@", urlHalf, receivedStreamReferenceNumber];
    NSURL *url = [NSURL URLWithString: mutableUrlString];
    NSData *data = [NSData dataWithContentsOfURL:url];
    [self convertData:data];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self start];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
编辑:

我合并了以下代码。。。但我正努力把这一切联系在一起。下面应该创建一个文件,将录制的流音频保存到该文件中。我想我得告诉AV录音机听AV播放器怎么说?再次感谢您的帮助:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [stopButton setEnabled:YES];
    [playButton setEnabled:YES];

    // Set the audio file
    NSArray *pathComponents = [NSArray arrayWithObjects:
                               [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                               @"xxx.mp3",
                               nil];
    NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

    // Setup audio session
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];


    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil];
    recorder.delegate = self;
    recorder.meteringEnabled = YES;
    [recorder prepareToRecord];
}
嗨,我一直在看AVRecorder。。。但我不知道如何实现它,以便我可以同时听到音频流和录制。非常感谢您的帮助。嗨,我一直在看AVRecorder。。。但我不知道如何实现它,以便我可以同时听到音频流和录制。非常感谢您的帮助。