3

我很困惑:

MPMoviePlayerViewController 和 MPMoviePlayerController

在 ios6 本地播放视频的最佳方式是什么?

这是我的代码

NSURL * url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @ "17" OfType: @ "mov"]];

     MoviePlayer = [[MPMoviePlayerViewController alloc]
                     initWithContentURL: url];
     [self presentMoviePlayerViewControllerAnimated: MoviePlayer];
     [moviePlayer.moviePlayer play];
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (moviePlayerPlaybackStateChanged :) name: MPMoviePlayerPlaybackStateDidChangeNotification object: nil];
}


-(void)moviePlayerPlaybackStateChanged:(NSNotification *)notification {


}
4

1 回答 1

8

MPMoviePlayerViewController 用于播放全屏视频,主要用于手机。

MPMoviePlayerController 可用于嵌入视频,即不能在任何 iPad 上全屏显示。您需要在情节提要中将一个空视图拉到您的场景中,并为其提供所需的大小。然后,在代码中,将电影播放器​​放在该子视图中。您的代码的第一部分应该在 viewDidLoad 中;

//movieplayer initialization
NSString *path = [[NSBundle mainBundle] pathForResource:@"videoName" ofType:@"m4v"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer setControlStyle:MPMovieControlStyleNone]; // for custom controls, for default controls you can leave this line out.

这部分进入 viewWillAppear;

moviePlayer.repeatMode = MPMovieRepeatModeOne; // for looping
[moviePlayer.view setFrame: self.videoSuper.bounds]; 
[self.videoSuper addSubview: moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

其中 videoSuper 是故事板中添加的子视图。确保正确连接;

//in .h
@property (weak, nonatomic) IBOutlet UIView *videoSuper;
于 2012-10-24T04:03:34.290 回答