问题描述
我正在开发一个应用程序,其中我必须同时录制一首歌曲和一个wav文件.我正在播放iPod音乐库中的歌曲,并在视图控制器上放置了一个按钮, WAV文件开始,但是当我开始使用AVAudioRecorder录制时,WAV文件停止工作.这是我的ipod音乐库的代码:-
I'm developing an App in which i have to record a song and a wav file at a same time.I'm playing song from iPod Music libraries and on a view controller i have placed a button on click of which an wav file starts but when i start recording using AVAudioRecorder,my wav file stop working.This is my ipod music library's code:-
- (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文件的代码:-
and this is my code by which i m playing wav file:-
-(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录制这两个...请帮忙.谢谢...
I'm recording these two by AVAudioRecorder...Please help.Thanks in advance...
推荐答案
创建音频会话
audioSession.delegate = self;
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
现在在AVAudioPlayer中播放文件,并同时开始使用AVAudioRecorder录音
Now play your file in AVAudioPlayer and at same time start recording using AVAudioRecorder
这篇关于如何录制同时播放AVPlayer和WAV文件的歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!