如何录制同时播放AVPlayer和wav文件的歌曲?

时间:2012-04-09 10:47:05

标签: iphone objective-c avaudioplayer avplayer avaudiorecorder

我正在开发一个应用程序,我必须同时录制一首歌和一个wav文件。我正在播放iPod音乐库和视频控制器上的歌曲,我点击了一个按钮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记录这两个...... 请帮忙。谢谢...

1 个答案:

答案 0 :(得分:1)

创建音频

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

现在在AVAudioPlayer中播放您的文件,同时使用AVAudioRecorder开始录制