我在我的视图中以一定的大小和位置放置一个MPMoviePlayerController。这工作正常。但是,在某些情况下,我希望视频能够全屏播放。我的视图是UISPlitViewController的一部分,所以如果我只获得视图宽度,它不是全屏。我需要的是显示视频,好像用户点击了播放器控件中的双头箭头以最大化视频。
到目前为止,这是我的代码。任何人都可以填写强制全屏播放的缺失位吗?
- (void)viewDidLoad
{
[super viewDidLoad];
// FIND OUT HOW MANY VIDEOS ARE AVAILABLE
int videoCount = [[self videos] count];
// GET THE FILE NAME OF THE FIRST AVAILABLE VIDEO
NSString* fileName = [NSString stringWithFormat:@"%@.mp4", [self videos] objectAtIndex:0]];
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString *filePath = [path stringByAppendingPathComponent:fileName];
NSURL *url = [NSURL fileURLWithPath:filePath];
// PLACE THE MOVIE AT THE CORRECT LOCATION ON THE PAGE
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[moviePlayer view] setFrame:CGRectMake(100, 100, 600, 360)];
[[moviePlayer view] setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[[self view] addSubview:moviePlayer.view];
[moviePlayer play];
if(videoCount == 1)
{
-- MAXIMISE THE VIDEO TO FULL SCREEN AND LANDSCAPE --
}
}
由于
答案 0 :(得分:0)
根据Apple的文档,您只需将`MPMoviePlayerController设置为全屏:
[moviePlayer setFullscreen:YES animated:YES]
你试过这个吗?
答案 1 :(得分:0)
请使用MPMoviePlayerViewController因为MP4文件。当你使用MOV然后工作完美!!
MPMoviePlayerViewController *moviePlayerViewController;
-(void)PlayVedioController:(NSString*)videoUrl1
{
NSURL *fileURL = [NSURL URLWithString:videoUrl1];
moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
// Register for the playback finished notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerViewController.moviePlayer];
//Present
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
// Play the movie!
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[moviePlayerViewController.moviePlayer play];
}
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerViewController.moviePlayer];
[moviePlayerViewController release], moviePlayerViewController = nil;
}