视频作为IOS目标C中的启动画面。 任何帮助表示赞赏。
答案 0 :(得分:3)
Moorthy 您可以使用AVPlayer和AVPlayerViewController帮助来实现此目的。
我会详细解释你做这个技巧的过程。
第一步 在Xcode项目中添加以下框架并将其导入Appdelegate。
第二步 在Appdelegate didFinishLaunchingWithOptions方法
中添加以下代码 // grab a local URL to our video
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:@"myvideo" withExtension:@"mov"];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
controller.showsPlaybackControls = false;
controller.view.frame = self.window.frame;
controller.modalPresentationStyle = UIModalPresentationFullScreen;
self.window.rootViewController = controller;
[player play];
// Adding Observer for your video file,
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(videoDidFinish:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
第三步
视频完成后,您将进入这个地方
- (void)videoDidFinish:(id)notification {
AVPlayerItem *p = [notification object];
//do something with player if you want
//Remove Observer
[[NSNotificationCenter defaultCenter] removeObserver:self];
//your initial view can proceed from here
[self ProccedToYourViewController];
}
一些提示
您可以通过添加淡入和淡出动画来顺畅地停止视频播放,我会告诉您我是如何为自己做的
//AvplayerViewController View(Video View).
[self.controller.view setAlpha:1.0f];
[UIView animateWithDuration:2.0f animations:^{
//AvplayerViewController View(Video View) setting to hide.
[self.controller.view setAlpha:0.0f];
//initialview(Your Initial View) that add as window root now
self.window.rootViewController = initialview;
[initialview.view setAlpha:1.0f];
[self.window makeKeyAndVisible];
} completion:nil];
现在你准备好了。干杯