how can i record a song which is playing with AVPlayer and an wav file at a same time?

梦想的初衷 提交于 2020-01-25 05:01:08

问题


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];  
}

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);
}

I'm recording these two by AVAudioRecorder... Please help.Thanks in advance...


回答1:


create audiosession

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

Now play your file in AVAudioPlayer and at same time start recording using AVAudioRecorder



来源:https://stackoverflow.com/questions/10072097/how-can-i-record-a-song-which-is-playing-with-avplayer-and-an-wav-file-at-a-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!