1
我试图播放电影全屏,AVCaptureSession显示在角落(认为FaceTime)的小视图中的前置摄像头。如果我将播放视频的代码注释掉,FrontCamera显示完美地放在我放置包含它的UIView的角落。如果我让代码按原样运行,则只显示视频,覆盖包含AVCapture的subLayer的UIView。另一个子组织是电影和时间线栏控件的控件,我想知道是否有办法在MPMoviePlayerController中禁用它。以下是我正在使用的代码:MPMoviePlayerController涵盖所有其他视图
AVCaptureSession *session = [[AVCaptureSession alloc] init];
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;
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
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);
}
[session addInput:input];
[session startRunning];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *proud = [[documentsDirectoryPath stringByAppendingPathComponent:@"proud"] stringByAppendingPathComponent:selectedCountry];
NSURL *movieURL = [[NSURL fileURLWithPath:proud] retain];
self.player =
[[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[player prepareToPlay];
player.allowsAirPlay = NO;
player.scalingMode = MPMovieScalingModeFill;
self.player.view.frame = self.view.frame;
[self.view addSubview: player.view];
[self.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];
vImagePreview是在头中声明的IBOutlet UIView属性。
太棒了,谢谢。我最终将其插入其他子视图的下方。 – user717452 2012-04-24 04:45:49