【问题标题】:how can i record a song which is playing with AVPlayer and an wav file at a same time?如何同时录制使用 AVPlayer 和 wav 文件播放的歌曲?
【发布时间】:2012-04-09 10:47:05
【问题描述】:

我正在开发一个应用程序,我必须在其中同时录制歌曲和 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 录制这两个... 请帮忙。在此先感谢...

【问题讨论】:

    标签: iphone objective-c avaudioplayer avplayer avaudiorecorder


    【解决方案1】:

    创建音频会话

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2015-04-01
      相关资源
      最近更新 更多