MediaPlayer MPMoviePlayerController - 不在横向播放视频
真的希望有人能帮忙,我可以通过点击按钮来播放我的视频,但他们总是以纵向模式播放,我真的希望他们能够在全屏播放。MediaPlayer MPMoviePlayerController - 不在横向播放视频
这里是我在这里使用的代码,我在这里添加了一些代码,有人说它在他们的情况下修复它,但毫无疑问地弄乱了语法是某种方式。
请别人让我摆脱我的苦难&告诉我我做错了什么明显的事情。
#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
我认为你需要更改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];
}
使用MPMoviePlayerViewController代替的MPMoviePlayerController。它会处理方向,控制方式等。我把它称为https://*.com/a/4911172/3346048。
MPMoviePlayerViewController *playerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:playerView];
并在AppDelegate.m中声明以下函数。这将限制在所有情况下的方向为纵向,只会改变当视频播放
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{ 如果([self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController类]){ 返回UIInterfaceOrientationMaskAll; } else { // NSLog(@“orientation should change”); return UIInterfaceOrientationMaskPortrait; }
}
请告诉理由反对投票我的回答 – sonal 2015-03-13 10:34:48
请帮助:(我真的不能工作了这一点 – Nick 2012-02-27 11:10:24
现在面临同样的问题。已经尝试了所有的帖子在那里。毫无帮助 – Anand 2012-03-05 15:04:05