0
在我的應用程序中我想在MPMoviePlayerController中播放視頻,但是當我運行該應用程序時,它僅顯示白色框架。下面的代碼:MPMoviePlayerController僅顯示白色背景
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Problems" ofType:@"MP4"];
NSLog(@"path: %@", moviePath);
//NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
player.view.frame = CGRectMake(0, 0, 700, 700);
player.view.backgroundColor = [UIColor whiteColor];
player.controlStyle = MPMovieControlStyleDefault;
player.shouldAutoplay = YES;
[self.detailView addSubview:player.view];
[player play];
編輯:我想這代碼,而不是,並增加了@property了的MPMoviePlayerController。我現在可以看到玩家,但應用程序崩潰並且斷點無法識別位置。下面的代碼:
self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Problems" ofType:@"MP4"]]];
[self.player.view setFrame:CGRectMake(0, 0, 320, 320)];
[self.detailView addSubview:self.player.view];
[self.player play];