ios - 视频播放适用于 iPhone 但不适用于 iPad

标签 ios objective-c video cocos2d-iphone

我试图让视频在 OpenGL 上下文之上播放,它在 iPhoneX 上运行良好,但在我的 iPad Pro 上却出现黑屏。音频播放,并且日志中没有错误表明可能出现问题。

这是我的代码:

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];

我知道 480x320 在 12 英寸 iPad 上非常小,但父 View 设置了其scaleX/scaleY 属性来放大它(同样,这在 iPhoneX 上运行良好,甚至对于 iPad 上的 OpenGL 内容也适用) )

该代码最初使用已弃用的 MPMediaPlayerController,我也尝试使用 MPMediaPlayerViewController,就像我尝试了 StackOverflow 上针对黑屏视频建议的所有各种巫术技巧一样,结果始终相同。

谁有类似的经历并有解决方法吗?

最佳答案

添加到 [[DirectorsharedDirector] openGLView].layer.superLayer 而不是 [[DirectorsharedDirector] openGLView].layer 修复了问题。

我仍然不明白为什么 iPhone 和 iPad 之间会有所不同,或者为什么如果它不起作用,它不会在 iPad 上抛出某种错误。 (FWIW,两者都适用于 iPhone)

关于ios - 视频播放适用于 iPhone 但不适用于 iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57288020/

相关文章:

iphone - iPhone 中的 VoIP 实现

ios - 如何制作一系列句子?

Android:在 Opengl 应用程序中播放视频的最佳方式

javascript - 奇怪的 IE,Javascript 只能在开发模式下工作(F12)

iphone - iOS - 知道模态视图何时被关闭

ios - 在最新的 xcode 5 中分别添加到 Storyboard 中的 UIViewController 后看不到 UIView

ios - UIView SubView UIButton 不响应触摸

ios - 如何使用 keyboardDismissMode = .interactive 为键盘滚动设置动画

ios - 发送到实例 0x8c9a6d0 的无法识别的选择器

java - vlcj 媒体播放器 : how to detect when video has finished playing