Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone MPMoviePlayerController使所有其他音频变软(MP完成后)_Iphone_Mpmovieplayercontroller_Avcapturesession_Avaudiosession - Fatal编程技术网

Iphone MPMoviePlayerController使所有其他音频变软(MP完成后)

Iphone MPMoviePlayerController使所有其他音频变软(MP完成后),iphone,mpmovieplayercontroller,avcapturesession,avaudiosession,Iphone,Mpmovieplayercontroller,Avcapturesession,Avaudiosession,我有一个应用程序可以播放一些背景音乐,当按下某个按钮时,它会使用导航控制器推送一个新视图。这个新视图有一个MPMoviePlayerController和一个带有共享音频会话的AVCaptureSession。这种观点被否定后,背景中的声音与过去相比真的很柔和。是什么导致演奏后音量变得如此低沉 NSError* error4 = nil; AVAudioSession* audioSession = [AVAudioSession sharedInstance]; if (![audioSess

我有一个应用程序可以播放一些背景音乐,当按下某个按钮时,它会使用导航控制器推送一个新视图。这个新视图有一个MPMoviePlayerController和一个带有共享音频会话的AVCaptureSession。这种观点被否定后,背景中的声音与过去相比真的很柔和。是什么导致演奏后音量变得如此低沉

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];

音频会话可能正在“回避”背景音乐。您可能希望将属性“kAudioSessionProperty\u othermixableaudioshoulldduck”设置为false以禁用该属性。

我现在就知道了。我把分类设置为播放和录制。我将其更改为Ambient(它还允许在播放音频时录制音频),并删除了OverrideCategoryMixWithOthers的属性,只留下

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

我该如何改变财产?我将此添加到代码中:
OSStatus propertySetror=0;UInt32 allowMixing=真;PropertySetror |=AudioSessionSetProperty(kAudioSessionProperty)或其他MixeableAudioShouldDuck、sizeof(allowMixing)和allowMixing
并且我可以在仍然与其他人一起使用OverrideCategoryMix时使用它吗?更改allowMixing=false;我想你可以将它与其他属性一起使用,因为它只是告诉它在混音时要做什么,但我不是肯定的。它不工作,弄乱了AVCaptureSession正在进行的录制,并且在完成后音频仍然几乎静音。hmmm。好吧,这听起来确实像是在逃避,因为我最近使用了这个功能。另一个建议是研究useApplicationAudioSession属性,它是MPMovieController的一部分。默认情况下,设置为“是”,但我不知道这是否会破坏其他东西。(编辑)nm我看到你已经把它设置为是了,我现在已经弄明白了。我把分类设置为播放和录制。我将其更改为Ambient(它还允许在播放音频时录制音频),并删除了OverrideCategoryMixWithOthers的属性,只保留了ducking部分,并将allowmixing的值设置为true,现在所有这些都可以一起工作了。