简体   繁体   中英

Video playback works on iPhone but not on iPad

I'm trying to get video to play on top of an OpenGL context and it works fine on an iPhoneX, but on my iPad Pro I get a black screen. Audio plays and there are no errors in the log to indicate that something might be wrong.

This is the code I have:

NSString *path = [[NSBundle mainBundle] pathForResource:title ofType:@"m4v"];

self.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];

CGRect rect = CGRectMake(0, 0, 480, 320);
self.playerLayer.frame = rect;

[[[Director sharedDirector] openGLView].layer addSublayer:self.playerLayer];

[_player play];

I'm aware that 480x320 is very small on a 12" iPad, but the parent view has its scaleX/scaleY properties set to upsize it (again, this works fine on iPhoneX, and even for the OpenGL content on the iPad)

The code was originally using the deprecated MPMediaPlayerController, and I tried using MPMediaPlayerViewController as well, just as I've tried all of the various voodoo tricks suggested here on StackOverflow for black-screen video and the result is always the same.

Anyone with similar experience and a way to fix it?

Adding to [[Director sharedDirector] openGLView].layer.superLayer instead of [[Director sharedDirector] openGLView].layer fixed the problem.

I still don't get why this would be different between iPhone and iPad, or why it doesn't throw some kind of error on the iPad if it doesn't work. (FWIW, both works on the iPhone)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM