2012-04-24 58 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

相關問題