Desidero riprodurre il file audio durante la registrazione con la fotocamera. Ho usato AVAudioPlayer per riprodurre audio e AVCamCaptureManager per la registrazione.Riproduzione di file audio durante la registrazione di video su iOS
Ma quando l'audio inizia a suonare, la schermata di anteprima si sta congelando. Cosa dovrei fare?
Grazie per il vostro aiuto. Ecco il codice. (Sto lavorando all'esempio di AVCam.)
Questa è la parte di anteprima.
if ([self captureManager] == nil) {
AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
[self setCaptureManager:manager];
[[self captureManager] setDelegate:self];
if ([[self captureManager] setupSession]) {
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = CGRectMake(0, 0, 480, 320);
[newCaptureVideoPreviewLayer setFrame:bounds];
if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:[DeviceProperties setPreviewOrientation]];
}
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
[self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[[self captureManager] session] startRunning];
});
[self updateButtonStates];
}
E questo fa parte del gioco audio.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", sound] ofType:@"wav"]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer play];
Se uso AudioServicesPlaySystemSound normale, senza gelo ma questa volta funziona solo su viewDidLoad.
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileRef;
soundFileRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) CFBridgingRetain(@"sound"), CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileRef, &soundID);
AudioServicesPlaySystemSound(soundID);
Potresti pubblicare il tuo codice? – Robert
Eventuali aggiornamenti su questo? Mi stavo chiedendo se è possibile attivare la fotocamera (non necessariamente registrare video) durante la registrazione audio con AVAudioPlayer. –
ho anche lo stesso problema. Cosa faccio ora .. –