真的希望有人可以提供帮助,我可以通过点击按钮让我的视频播放,但他们总是以纵向模式播放,我真的希望他们以全屏风格播放。
以下是我在这里使用的代码,我在这里添加了一些代码,有人说在他们的情况下修复了它,但无疑有些方法搞砸了语法。
请有人把我从痛苦中解脱出来告诉我,我做错了什么显而易见的事。
#import "SecondViewController.h"
@implementation SecondViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BG.png"]];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Allerjen Exclusive" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
UIView * playerView = [moviePlayerController view];
[playerView setFrame: CGRectMake(0, 0, 480, 320)];
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f);
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[playerView setTransform: landscapeTransform];
moviePlayerController.fullscreen = TRUE;
moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
@end
答案 0 :(得分:0)
我认为你需要在方向改变时改变moviePlayer视图的框架, 使用以下功能:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
/* Size movie view to fit parent view. */
CGRect viewInsetRect = CGRectInset ([self.view bounds],20,20);
[[[self moviePlayerController] view] setFrame:viewInsetRect];
}
答案 1 :(得分:-1)
使用MPMoviePlayerViewController而不是MPMoviePlayerController。它将处理方向,控制风格等。我提到https://stackoverflow.com/a/4911172/3346048也是如此。
MPMoviePlayerViewController *playerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:playerView];
并在AppDelegate.m中声明以下函数。这将在所有情况下将方向限制为纵向,并且仅在播放视频时更改
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{ if([[self.window.rootViewController presentsViewController] isKindOfClass:[MPMoviePlayerViewController class]]) { 返回UIInterfaceOrientationMaskAll; } 其他 { // NSLog(@"方向应该改变"); 返回UIInterfaceOrientationMaskPortrait; }
}