0

특정 배경 음악을 재생하는 앱이 있습니다. 특정 버튼을 누르면 내비게이션 컨트롤러를 사용하여 새보기가 푸시됩니다. 새로운 뷰에는 MPMoviePlayerController와 AVCaptureSession에 공유 AudioSession이 있습니다. 보기가 닫히고 나면 백그라운드의 사운드는 원래의 사운드와 비교할 때 실제로 부드럽습니다. 연주 한 후에 볼륨을 너무 부드럽게 만드는 것은 무엇입니까?MPMoviePlayerController는 다른 모든 오디오를 부드럽게 만듭니다 (MP 완료 후)

NSError* error4 = nil; 
AVAudioSession* audioSession = [AVAudioSession sharedInstance]; 
if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error4]) { 
    NSLog(@"AVAudioSession setCategory failed: %@", [error4 localizedDescription]); 
} 

// Set audio session property "allow mixing" to true so audio can be recorded while it is playing 
UInt32 allowMixing = true; 
OSStatus status = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing); 
if (status != kAudioSessionNoError) { 
    NSLog(@"AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers) failed: %ld", status); 
} 

// Activate the audio session 
error4 = nil; 
if (![audioSession setActive:YES error:&error4]) { 
    NSLog(@"AVAudioSession setActive:YES failed: %@", [error4 localizedDescription]); 
} 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectoryPath = [paths objectAtIndex:0]; 

NSString *proud = [[documentsDirectoryPath stringByAppendingPathComponent:@"imissyou"] stringByAppendingPathComponent:selectedCountry]; 

NSURL *movieURL = [[NSURL fileURLWithPath:proud] retain]; 
player = 

[[MPMoviePlayerController alloc] initWithContentURL: movieURL]; 
player.useApplicationAudioSession=YES; 

[player prepareToPlay]; 
player.controlStyle = MPMovieControlStyleNone; 
player.allowsAirPlay = NO; 
player.scalingMode = MPMovieScalingModeFill; 

player.view.frame = self.view.frame; 

[self.view insertSubview:player.view belowSubview:vImagePreview]; 

[player setFullscreen:YES animated:YES]; 

// ... 

[[NSNotificationCenter defaultCenter] 
addObserver:self 
selector:@selector(movieFinishedCallback:) 
name:MPMoviePlayerPlaybackDidFinishNotification 
object:player]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:player]; 


[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayerWillExitFullscreen:) 
              name:MPMoviePlayerWillExitFullscreenNotification 
              object:player]; 


[player play]; 


session = [[AVCaptureSession alloc] init]; 
[session beginConfiguration]; 
session.sessionPreset = AVCaptureSessionPresetMedium; 

CALayer *viewLayer = self.vImagePreview.layer; 
NSLog(@"viewLayer = %@", viewLayer); 

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; 
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
captureVideoPreviewLayer.frame = self.vImagePreview.bounds; 
[captureVideoPreviewLayer setCornerRadius:14]; 
[captureVideoPreviewLayer setBorderWidth:3.0]; 
[captureVideoPreviewLayer setBorderColor:[[UIColor whiteColor] CGColor]]; 
[[vImagePreview layer] setCornerRadius:14]; 


[[vImagePreview layer] setBorderWidth:3.0]; 


[[vImagePreview layer] setBorderColor:[[UIColor whiteColor] CGColor]]; 

[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer]; 
[captureVideoPreviewLayer release]; 
AVCaptureDevice *device = [self frontFacingCameraIfAvailable]; 
NSError *error = nil; 
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 
if (!input) { 
    // Handle the error appropriately. 
    NSLog(@"ERROR: trying to open camera: %@", error); 
} 

AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; 
NSError *error2 = nil; 
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error2]; 






AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init]; 

NSString *archives = [documentsDirectoryPath stringByAppendingPathComponent:@"archives"]; 
NSString *editedfilename = [[selectedCountry lastPathComponent] stringByDeletingPathExtension]; 
NSString *datestring = [[editedfilename stringByAppendingString:@" "] stringByAppendingString:currentTime]; 
NSLog(@"%@", datestring); 
NSString *outputpathofmovie = [[archives stringByAppendingPathComponent:datestring] stringByAppendingString:@".mp4"]; 
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputpathofmovie]; 
[session addInput:input]; 
[session addInput:audioInput]; 
[session addOutput:movieFileOutput]; 
[session commitConfiguration]; 
[session startRunning]; 
[movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self]; 
[movieURL release]; 
[outputURL release]; 

답변

0

지금 알아 냈습니다. PlayAndRecord로 카테고리를 설정했습니다. 나는 속성을 변경 가야합니까 어떻게 바로

OSStatus propertySetError = 0; 
UInt32 allowMixing = true; 
propertySetError |= AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(allowMixing), &allowMixing); 
1

오디오 세션이 배경 음악을 "더킹 (ducking)"할 수 있습니다. 이 기능을 사용하지 않으려면 "kAudioSessionProperty_OtherMixableAudioShouldDuck"속성을 false로 설정하십시오.

+0

를 떠나, 그리고 OverrideCategoryMixWithOthers의 제거 특성 (오디오를 재생하는 동안 오디오를 녹음 할 수 있습니다) 주위로 변경? 나는 이것을 코드에 추가했다 : 'OSStatus propertySetError = 0; UInt32 allowMixing = true; propertySetError | = AudioSessionSetProperty (kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof (allowMixing), allowMixing); OverrideCategoryMixWithOthers를 사용하면서이 코드를 사용할 수 있습니까? – user717452

+0

allowMixing = false로 변경하십시오. 나는 그것이 혼합 될 때 무엇을해야하는지 말한 이후로 다른 속성과 함께 사용할 수 있다고 생각하지만 나는 긍정적이지 않습니다. – rooster117

+0

AVCaptureSession이 녹음 한 녹음을 엉망으로 만들었지 만 오디오가 끝난 후에도 여전히 소리가 거의 나지 않았습니다. – user717452