gpt4 book ai didi

iphone - MediaPlayer MPMoviePlayerController - 不在横向播放视频

转载 作者:行者123 更新时间:2023-12-01 17:10:15 26 4
gpt4 key购买 nike

真的希望有人可以提供帮助,我可以通过单击按钮来播放我的视频,但是它们总是以纵向模式播放,我真的希望它们以全屏横向播放。

这是我在这里使用的代码,我从这里添加了一些代码,有人说在他们的情况下修复了它,但毫无疑问在某种程度上弄乱了语法。

请有人让我摆脱痛苦并告诉我我做错了什么明显的事情。

#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 View 的框架,
使用以下功能:

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
/* Size movie view to fit parent view. */
CGRect viewInsetRect = CGRectInset ([self.view bounds],20,20);
[[[self moviePlayerController] view] setFrame:viewInsetRect];

}

关于iphone - MediaPlayer MPMoviePlayerController - 不在横向播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9453567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com