在应用程序启动时启动视频无法通过iOS

时间:2015-06-22 11:43:02

标签: ios objective-c xcode mpmovieplayercontroller

每当用户在iOS设备上打开应用程序时,我想要显示一个小视频(3秒视频)。 (如果应用程序是从内存中打开的,则不显示视频)

我将我的“仪表板”视图作为根视图控制器。

我搜索了SO和其他网站上的所有链接,但都没有帮助。

有时我的视频正在运行但后来的应用程序崩溃了。

我的仪表板视图来自“Main.storyboard”,但故事板上没有控件。 只通过故事板完成导航栏的链接。

这是我的代码。

2a139a55

nslog正确打印视频路径。 像

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showVideo];
}


- (void)showVideo
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSLog(@"video path :- %@",url);
    self.navigationController.navigationBar.hidden = YES;
    self.videoController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    self.videoController.moviePlayer.controlStyle = MPMovieControlStyleNone;
    //[self presentMoviePlayerViewControllerAnimated:videoController];
    [self.navigationController pushViewController:self.videoController animated:NO];

    [self.videoController.moviePlayer play];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.videoController];
}

- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
    self.navigationController.navigationBar.hidden = NO;
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];

    [self.videoController.view removeFromSuperview];
    [self.videoController.moviePlayer stop];
    self.videoController = nil;

    [self.navigationController popViewControllerAnimated:NO];
    //[self.view removeFromSuperview];
}

但App崩溃了, 它既不显示视频,也显示仪表板,而不是直接显示仪表板。

任何人都可以指导我,我做错了什么。

提前致谢。

如果错误地错过了SO上的任何链接,请同时提供。 感谢。

2 个答案:

答案 0 :(得分:1)

尝试调用这样的方法,

- (void)viewDidLoad
{
    [super viewDidLoad];        
    [self performSelector:@selector(showVideo) withObject:nil afterDelay:0.1f]; 
}

答案 1 :(得分:0)

请在以下路径下启用“启用僵尸对象”选项: 编辑方案 - >诊断 - >启用Zombie Objects

让我知道日志。

相关问题