【问题标题】:Video playback works on iPhone but not on iPad视频播放适用于 iPhone 但不适用于 iPad
【发布时间】:2019-07-31 09:54:14
【问题描述】:

我试图让视频在 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 上非常小,但父视图的 scaleX/scaleY 属性设置为放大它(同样,这在 iPhoneX 上运行良好,甚至适用于 iPad 上的 OpenGL 内容)

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

任何有类似经验和解决方法的人?

【问题讨论】:

    标签: ios objective-c video cocos2d-iphone


    【解决方案1】:

    添加到 [[Director sharedDirector] openGLView].layer.superLayer 而不是 [[Director sharedDirector] openGLView].layer 解决了这个问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多