2013年4月1日 星期一
實作APP開場影片
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSLog(@"didFinishLaunchingWithOptions");
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"newhouse" ofType:@"MOV"]];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
//播放器參數設定
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
self.moviePlayer.repeatMode = MPMovieRepeatModeNone;
self.moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin
|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin;
//設定播放器大小
[self.moviePlayer.view setFrame:self.window.rootViewController.view.bounds];
[self.window.rootViewController.view addSubview:self.moviePlayer.view];
//播放
[self.moviePlayer play];
//註冊通知中心,當影片播放完畢,進行回呼方法(playbackStateDidFinish)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateDidFinish)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer ];
//Hide video controls
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
//Play as soon as loaded
self.moviePlayer.shouldAutoplay = YES;
return YES;
}
- (void)playbackStateDidFinish{
//註銷通知中心
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
//停止播放
[self.moviePlayer stop];
//移除播放器
[self.moviePlayer.view removeFromSuperview];
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言