【问题标题】:Adding audio input to AVCaptureSession stops AVPlayer向 AVCaptureSession 添加音频输入会停止 AVPlayer
【发布时间】:2011-05-30 13:05:52
【问题描述】:

我正在开发一个音乐应用程序,其中通过使用 AVPLayer 播放的 m4v 视频文件显示乐谱,并使用 AVCaptureSession 来预览和记录演奏者随着乐谱演奏的视频和音频。

不幸的是,虽然 AVCaptureVideoPreviewLayer 在显示乐谱的同时显示实时视频,但当我尝试向 AVCaptureSession 添加音频输入时,AVPlayer 会暂停。

我曾尝试使用单独的 AVCaptureSession 进行预览层和音频录制,但这似乎没什么区别。

我是在尝试做不可能的事情,还是有办法同时播放视频/音频和录制视频/音频。

据我所知,Skype 和 Facetime 做的事情相似(尽管不完全相同)。

【问题讨论】:

    标签: iphone avplayer avcapturesession


    【解决方案1】:

    将音频会话类别设置为正确的属性 PlayandRecord。还将 allowmixwithothers 设置为 yes。

    【讨论】:

      【解决方案2】:

      试试这个。我只是为另一个项目做的,它可以工作

      -(IBAction)beepingSound2
      {
          //do this so that we can hear the scream and record the movie too
          [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
          UInt32 doSetProperty = 1;
      
          AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
      
          [[AVAudioSession sharedInstance] setActive: YES error: nil];
      
          [myAudioPlayer1 stop];
          NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"long_beep" ofType: @"mp3"];
          NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];    
          myAudioPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
          [myAudioPlayer1 play];
      }
      

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题,但它似乎在 iOS 7 中得到了修复。在 iOS 7 之前,我可以让 AVAudioRecorder 与 AVPlayer 同时工作,但不能让 AVCaptureSession 与音频一起工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-06-06
          相关资源
          最近更新 更多