我有使用MPMoviePlayerViewController的問題。我試圖初始化電影viewDidLoad
,然後播放電影touchesBegan
。但電影最初開始播放,並在touchesBegan
它只顯示完成的電影。MPMoviePlayerViewController電影不會被詢問
ViewController.h文件
@interface ViewController : UIViewController{
MPMoviePlayerController *moviePlayer;
MPMoviePlayerViewController *mpviewController;
MPMovieControlStyle controlStyle;}
- (IBAction)touchesBegan:(id)sender;
@property (nonatomic) MPMovieControlStyle controlStyle;
@end
ViewController.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view addSubview:mpviewController.view];
[moviePlayer play]; }
- (void)viewDidLoad
{
NSString *movpath = [[NSBundle mainBundle]
pathForResource:@"my_moviefile"
ofType:@"m4v"];
mpviewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:movpath]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mpviewController];
MPMoviePlayerController *mp = [mpviewController moviePlayer];
// [mp setMovieControlMode:MPMovieControlModeHidden];
// [mp.view setFrame:CGRectMake(0, 0, 250, 263)];
mp.controlStyle = MPMovieControlStyleNone;
[mp prepareToPlay];
[super viewDidLoad];
}
如果我把所有的代碼touchesBegan
它能正常工作,但電影仍然需要裝入,但我想預加載它,然後在完成播放時再做一些事情。
任何線索?
問候
Tim在下面有一個很好的建議。你可以檢查(通過插入一個NSLog語句),如果由於某種原因加載視圖時可能會調用touchesBegan。 – 2012-02-27 18:21:23
這樣做,電影仍然在播放,但如果我觸摸它播放第二次.... – spankmaster79 2012-02-27 18:33:24