
我的要求是
>我需要在使用UIImagePickerController录制视频时观看视频
>使用耳机我需要通过播放视频来收听音频
>需要将我的声音录制到录制视频
>只录制我的声音但不播放视频的音频.
每一件事都在工作,但4.播放视频的音频也与我的声音混合在一起.如何处理这种情况?我的最终目标是
>播放视频的输出是耳机
>录音输入是耳机麦克风
请帮我完成这件事.
解决方法 你的要求很有趣.所以你需要同时播放和录制,对吧?因此,您需要使用AVAudioSessioncategoryPlayAndRecord类别初始化音频会话.
[[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryPlayAndRecord error:&error];
因为您正在使用UIImagePickerController进行录制,所以您无法控制扬声器和麦克风.所以测试看它是否有效.
如果您仍有问题,我建议您使用AVCaptureSession录制没有音频的视频.看看这个例子如何使用它record-video-with-avcapturesession-2.
更新:在我的VOIP应用程序中,我在播放时使用AVAudioUnit进行录制.所以我认为唯一的方法是分别录制视频和音频,然后使用AVComposition将其组合成一部电影.使用AVCaptureSession仅录制视频并使用EZAudio录制音频. EZAudio使用AVAudioUnit进行记录,以便它可以正常工作.您可以在播放电影时通过录制音频对其进行测试,看看它是否有效.我希望它会有所帮助
更新:我测试过,只有你使用耳机或选择麦克风后它才有效.
这是经过测试的代码:
Nsstring *movIEPath = [[NSBundle mainBundle] pathForResource:@"vIDeovIEwdemo" ofType:@"mp4"]; NSURL *url = [NSURL fileURLWithPath:movIEPath]; // You may find a test stream at <http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8>. AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url]; AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem]; AVPlayerLayer *layer = [[AVPlayerLayer alloc] init]; [layer setPlayer:player]; [layer setFrame:CGRectMake(0,100,100)]; [self.vIEw.layer addSublayer:layer]; [player play]; dispatch_after(dispatch_time(disPATCH_TIME_Now,(int64_t)(1 * NSEC_PER_SEC)),dispatch_get_main_queue(),^{ // // Setup the AVAudioSession. EZMicrophone will not work properly on iOS // if you don't do this! // AVAudioSession *session = [AVAudioSession sharedInstance]; NSError *error; [session setcategory:AVAudioSessioncategoryPlayAndRecord error:&error]; if (error) { NSLog(@"Error setting up audio session category: %@",error.localizedDescription); } [session setActive:YES error:&error]; if (error) { NSLog(@"Error setting up audio session active: %@",error.localizedDescription); } // // Customizing the audio plot's look // // Background color self.audioPlot.backgroundcolor = [UIcolor colorWithRed:0.984 green:0.471 blue:0.525 Alpha:1.0]; // Waveform color self.audioPlot.color = [UIcolor colorWithRed:1.0 green:1.0 blue:1.0 Alpha:1.0]; // Plot type self.audioPlot.plottype = EZPlottypeBuffer; // // Create the microphone // self.microphone = [EZMicrophone microphoneWithDelegate:self]; // // Set up the microphone input UIPickerVIEw items to select // between different microphone inputs. Here what we're doing behind the hood // is enumerating the available inputs provIDed by the AVAudioSession. // self.inputs = [EZAudioDevice inputDevices]; self.microphoneinputPickerVIEw.dataSource = self; self.microphoneinputPickerVIEw.delegate = self; // // Start the microphone // [self.microphone startFetchingAudio]; self.microphoneTextLabel.text = @"Microphone On"; [[AVAudioSession sharedInstance] overrIDeOutputAudioPort:AVAudioSessionPortOverrIDeSpeaker error:nil]; }); 总结 以上是内存溢出为你收集整理的ios – 在播放其他视频时录制视频全部内容,希望文章能够帮你解决ios – 在播放其他视频时录制视频所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)