[英]iPhone SDK 4: video autorotation from MPMoviePlayerViewController
Could you please show an example of shouldAutorotateToInterfaceOrientation
method usage as a part of MPMoviePlayerViewController? 拜托你给的例子shouldAutorotateToInterfaceOrientation
方法用法MPMoviePlayerViewController的一部分吗? As far as I know, using shouldAutorotateToInterfaceOrientation
method is available not only for UIView but also for MPMoviePlayerViewController since SDK 3.2. 据我所知,使用shouldAutorotateToInterfaceOrientation
方法不仅可用于UIView的同时也为MPMoviePlayerViewController SDK 3.2以来。 I've been using it in UIView, in 3.1, but I don't understand how to use it in MPMoviePlayerViewController class. 我一直在3.1的UIView中使用它,但是我不明白如何在MPMoviePlayerViewController类中使用它。
This is what I have for now: 这是我现在拥有的:
-(IBAction) playMovie {
//declaring path to file and stuff...
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
MPMoviePlayerController *player = [playerViewController moviePlayer];
[self.view addSubview:playerViewController.view];
player.controlStyle = MPMovieControlStyleDefault;
player.shouldAutoplay = YES;
[player setFullscreen:YES animated:YES];
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
}
It works just fine but I need to know how to implement video autorotation. 它工作正常,但我需要知道如何实现视频自动旋转。 The method used for it in UIView does not help. UIView中用于它的方法无济于事。
Thanks. 谢谢。
Hm, sounds strange but I was sure this method must not be declared ouside playMovie block. 嗯,听起来很奇怪,但是我确定此方法一定不能声明为ideide playMovie块。 I was wrong, the following code is pasted as usual and it does what I need. 我错了,下面的代码像往常一样粘贴,并且可以满足我的需要。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
else {
return NO;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.