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