问题
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