2011-05-30 81 views
4

我正在開發音樂應用程序,其中音樂符號通過使用AVPLayer播放的m4v視頻文件顯示,並且AVCaptureSession用於預覽和錄製演奏者的視頻和音頻分數。將音頻輸入添加到AVCaptureSession中停止AVPlayer

不幸的是,雖然AVCaptureVideoPreviewLayer在顯示音樂符號時顯示實況視頻,但當我嘗試向AVCaptureSession添加音頻輸入時,AVPlayer會暫停。

我已經嘗試使用單獨的AVCaptureSession的預覽圖層和音頻記錄,但這似乎沒有什麼區別。

我想要做不可能的事,或者有沒有辦法同時播放視頻/音頻和錄製視頻/音頻。

據我所見,Skype和Facetime可以做類似的事(雖然不完全一樣)。

回答

0

將音頻會話類別設置爲正確的屬性PlayandRecord。同時設置allowmixwithothers爲yes。

0

試試這個。我只是做了它的另一個項目和它的作品

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

我有同樣的問題,但它似乎被固定在iOS的7此前的iOS 7,我可以得到AVAudioRecorder與AVPlayer同時工作,但不帶音頻的AVCaptureSession。