-->

我怎么可以录制一首歌与AVPlayer和WAV文件播放在同一时间?(how can i record

2019-10-16 14:31发布

我开发一个应用程序在我所录制的歌曲,并在同一time.I'm从iPod中的音乐库和视图控制器上播放的歌曲wav文件我已经把上点击一下按钮,一个wav文件的开始但是当我开始使用AVAudioRecorder记录,我的wav文件停止工作。 这是我的iPod音乐库中的代码: -

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) collection 

{
MPMediaItem *item = [[collection items] objectAtIndex:0];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

[self dismissModalViewControllerAnimated: YES];


// Play the item using AVPlayer


AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player play];  
}

这是我的代码由即时通讯播放wav文件: -

-(void)playAudio:(NSString *)path
{
SystemSoundID soundIDWav;
NSString *sound = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath], @"/wavFile.wav"];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundIDWav);
AudioServicesPlaySystemSound(soundIDWav);
}

我录制这两个由AVAudioRecorder ...请help.Thanks提前...

Answer 1:

创建audiosession

audioSession.delegate = self;
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];

现在,在AVAudioPlayer播放文件,并在同一时间开始使用AVAudioRecorder记录



文章来源: how can i record a song which is playing with AVPlayer and an wav file at a same time?