I don't believe you can present a view controller in viewDidLoad. I am away from my computer, so I can't confirm right now, but I do not believe the presenting view controller's view is in the view hierarchy yet during viewDidLoad (exactly as the error message says).
On Tue, May 9, 2017 at 8:31 AM, Dave <[email protected]> wrote: > Hi, > > I’m tying to get a movie to play in iOS. > > I have this in a View Controller. When I run it, it seems to play the file > as I hear Audio but I get this message in the log: > > Warning: Attempt to present <AVPlayerViewController: 0x7f945a814400> on > <ViewController: 0x7f9458f056e0> whose view is not in the window hierarchy! > > I’ve search for help on this but I get hundreds of solutions using all > kinds of different techniques but none of them work. The Apple > Documentation is totally useless from what I can see and offers no working > solutions to build upon that I can find. > > Here is the code: > > -(void) viewDidLoad > { > AVPlayerViewController* myViewController; > AVPlayer* myPlayer; > NSURL* myMovieFileURL; > > [super viewDidLoad]; > > myMovieFileURL = [[NSBundle mainBundle] URLForResource:@"Demo-ENG-EX-001" > withExtension:@"mp4"]; > myPlayer = [[AVPlayer alloc] initWithURL:myMovieFileURL]; > > myViewController = [[AVPlayerViewController alloc] init]; > [self presentViewController:myViewController animated:YES completion:nil]; > > myViewController.player = myPlayer; > [myPlayer play]; > } > > I’m guess that I need to add a view to the AVPlayerViewController or vice > versa? > > Thanks in advance for any help. > > All the Best > Dave > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/vast.grapes%40gmail.com > > This email sent to [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
