0

私はいくつかのバックグラウンドミュージックを演奏するアプリケーションを持っています。特定のボタンを押すとナビゲーションコントローラを使用して新しいビューをプッシュします。その新しいビューには、MPMoviePlayerControllerと共有AudioSessionを持つAVCaptureSessionがあります。そのビューが解除された後、バックグラウンドのサウンドは、それがどうだったかと比べて本当に柔らかいです。演奏後に音量を落ち着かせる原因は何ですか?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

オーディオセッションがバックグラウンドミュージックを「ダッキング」している可能性があります。これを無効にするには、プロパティ "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

関連する問題