2012-04-24 56 views
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属性。

回答

1

默认情况下,视图将显示最后添加在最上面。因此,当该代码将电影播放器​​视图:

[self.view addSubview:player.view]; 

这是对一切之上,具有框架父边界的全尺寸。如果有一些子视图,你想留在上面,你可以把它放回顶部添加电影播放后...

[self.view bringSubviewToFront:otherSubview]; 

..或将影片播放器下方它与开始...

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

quite a few other methods available来控制视图层次结构。希望有所帮助。

+0

太棒了,谢谢。我最终将其插入其他子视图的下方。 – user717452 2012-04-24 04:45:49

相关问题