- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的视频播放器遇到了奇怪的情况,其核心代码与我制作的早期应用程序中的代码相比没有太大变化。问题是:我插入一个“_loadingLayer”(一个表示视频正在加载的 CATextLayer),然后观察 AVPlayer 的 currentItem 的状态属性以找出何时删除“_loadingLayer”并将其替换为我实际的“_playerLayer” 。这是我的 KVO 代码:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ((object == _playerLayer) && (_playerLayer.player.currentItem.status == AVPlayerItemStatusReadyToPlay)) {
[CATransaction setAnimationDuration:1.8];
_loadingLayer.opaque = NO;
if (_playerLayer.readyForDisplay) {
NSLog(@"Should be ready now.");
}
[self addPlayerLayerToLayerTree];
}
}
我的问题是视频正在启动,但只有音频正在播放 - 图层保持黑色。当我插入上面的 NSLog 语句时,我发现了原因:显然,虽然 currentItem 的状态是“AVPlayerItemStatusReadyToPlay”,但播放器层实际上并未准备好显示。这对我来说毫无意义——这似乎违反直觉。有人可以给我一些指导吗?
我能够通过将 _playerLayer 的背景颜色设置为红色来验证它是否已添加到图层树中。
我认为可能相关的另一件奇怪的事情......我在调试器控制台中看到了这些消息:
PSsetwindowlevel,错误设置窗口级别(1000)CGSSetIgnoresCycle:错误 1000 设置或清除窗口标签
提前致谢。这是来自 Apple 开发论坛的交叉帖子。
最佳答案
我们遇到了类似的问题,并追踪到我认为是 iOS 5.1(可能还有更早版本)中的错误。它在 iOS 6.0 中得到修复。由于我在任何地方都找不到解决方案,因此我正在为 future 遇到此问题的人写一篇长文。
如果 AVPlayerItem 在获取 AVPlayerLayer 之前报告 AVPlayerStatusReadyToPlay 状态,则 AVPlayer 将永远不会报告它已准备就绪。
所以当你这样做时:
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
确保后面跟着:
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
并且两者之间没有太多代码(如果有的话)。
我构建了一个测试装置,使其在 100% 的时间里正常工作,或者在 100% 的时间里失败。请注意,查看实际应用程序中发生的情况可能很棘手,因为视频的加载时间不同,这将影响playerItem报告AVPlayerStatusReadyToPlay的速度。
如果您想在您的应用程序中进行测试,请将其放入一个简单的 View 中。以下内容在 iOS 5.1 上不起作用(即您将听到音频但看不到视频)。如果您将 loadPlayerLayer 切换为在 loadPlayer 末尾调用,则它将始终有效。
为 future 的读者提供的后续内容:几个玩家事件可以改变这个顺序,让你认为它正在工作。但它们是转移注意力的,因为它们无意中颠倒了加载顺序,使得playerLayer在AVStatusReadyToPlay之前被抓取。这些事件是:寻找视频、转到主屏幕然后重新激活应用程序、播放器切换到 HLS 视频内的不同视频/音频轨道。这些操作再次触发 AVStatusReadyToPlay,从而使playerLayer 在 AVStatusReadyToPlay 之前发生。
这是使用 Apple 测试 HLS 视频的测试工具:
-(void)loadPlayer
{
NSLog(@"loadPlayer invoked");
NSURL *url = [NSURL URLWithString:@"https://devimages.apple.com.edgekey.net/resources/http-streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"];
self.playerItem = [AVPlayerItem playerItemWithURL:url];
[self.playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:&kPlayerContext];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
}
-(void)loadPlayerLayer
{
NSLog(@"starting player layer");
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
[self.playerLayer addObserver:self forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:&kPlayerLayerContext];
[self.playerLayer setFrame:[[self view] bounds]];
[[[self view] layer] addSublayer:self.playerLayer];
}
-(void)observeValueForKeyPath:(NSString*)path ofObject:(id)object change:(NSDictionary*)change context:(void*) context
{
if(context == &kPlayerContext){
if([self.player status] == AVPlayerStatusReadyToPlay){
NSLog(@"Player is ready to play");
//Robert: Never works if after AVPlayerItem reports AVPlayerStatusReadyToPlay
if(!self.startedPlayerLayer){
self.startedPlayerLayer = YES;
[self loadPlayerLayer];
}
}
}
if(context == &kPlayerLayerContext){
if([self.playerLayer isReadyForDisplay] == YES){
NSLog(@"PlayerLayer says it's ready to display now");
[self playTheVideoIfReady];
}
}
}
关于macos - AV Foundation : Difference between currentItem being ready to play, 和 -[AVPlayer readyForDisplay] 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12654783/
我想加载带有本地回退的 foundation.min.js 的 CDN 版本。问题是:如何检测是否加载了 foundation.js? 我看到它是用 jQuery、modernizr、Bootstra
我从 v3 开始就一直在使用 Foundation,所以我没想到会出现这种困惑。 在这种特殊情况下,我需要一个固定宽度的左列(大 3),然后是一个流动/响应内容列(大 9)作为其余部分。
我在从最新的 Foundation 定制 Orbit 时遇到问题。来自 the docs : Orbit 选项此时只能在初始化时传入。 { timer_speed: 10000, animat
在以下非常基本的示例中,开关可以正常工作并且样式正确。如果我只是将 foundation.css 版本从 5.5.2 更改为 6.0.5,切换样式就会丢失。为什么开关在 Foundation 6.0
如何禁用中/小屏幕的顶部栏折叠? 我按照 Here 中的说明进行操作但无论我将最小宽度设置为什么,我都会得到相同的结果。 最佳答案 如果您使用的是 SCSS 版本,那么您可以修改断点。 $topbar
出于多种原因,复选框在最新的 Foundation (4.1.6) 中存在问题。有没有一种简单的方法可以阻止 Foundation 接管它们?我需要 custom我的类 form s 其他原因。我如何
我希望在显示模式窗口中播放的视频在模式窗口关闭时停止播放(谁不呢?)。通过将 iframe 源设置为空,可以使用 jQuery 轻松完成此操作。 但我不知道如何让它在回调中工作。模态窗口本身按预期运行
我最近开始将 Zurb Foundation 4 用于 Asp MVC 网站,但我不太明白开关控件应该如何工作。文档没有说太多 http://foundation.zurb.com/docs/comp
是否可以合并top-bar和 tab-bar ( Canvas 外)? 这个: 调整到手机尺寸时变成这样: 但我还想包括标签栏( Canvas 外)所以它变成这样 我无法想象这是如何做到的,我试图制作
我的问题是,在桌面上我喜欢先有菜单,然后是最右上角的标志。目前,当我将模板缩小到移动版本时, Logo 位于菜单下方,这并不令人满意。我想在菜单之前吃。我试过使用推/拉没有成功。 在移动 View 中
我直接从他们的网站 https://foundation.zurb.com/sites/docs/top-bar.html 复制了基础导航栏语法并且下拉菜单功能似乎不起作用 代码如下:
刚刚切换我的 Rails 项目以测试 Zurb Foundation 5,现在切换顶部栏菜单不起作用。 当视口(viewport)很小时,顶部栏菜单项消失并且菜单图标像以前一样显示,但是当我单击菜单图
如何在 Foundation 4 中以编程方式显示模态? 在 Foundation 3 中,我们有易于使用的 reveal() 方法。 您可以在 Foundation 4 中使用什么?请帮忙。 最佳答
我正在使用启用了 flexbox 的 Foundation 6 Zurb 模板,但按钮组的扩展功能不起作用。 当我添加扩展类时,最后一个按钮不会填满最后一个空格并掉到左侧的下一行。文本不再内联,按钮的
我正在使用 Zurb Foundation 并具有以下 html: Tab 1 Content of section 1. Tab
我正在尝试使用 zurb Foundation 5 显示模式。但是当我单击按钮时它不起作用并且无法打开。我正在使用这个 html 代码。 index Awesome. I ha
有什么我可以在命令行中输入的东西来找出我正在运行的版本吗? 最佳答案 在不了解您的具体情况的情况下,最简单的方法是在初始化 Foundation ( $(document).foundation();
Foundation 5 上曾经有一个“圆形”类,可以将按钮组转换为具有圆形边缘。我如何在 Foundation 6 中执行此操作? 最佳答案 这在 Foundation 6 中是不可能的。为了减小文
我正在使用 Zurb 的 Foundation 4.2.3,但是当我打印页面时,网格布局始终没有得到维护。 例如, XXX Lorem
作为 Zurb's Foundation 一部分的轨道 slider 好像加了一个类hide-for-small到导航。 我需要导航仍然显示,以便显示我的内容。我试过删除 hide-for-small
我是一名优秀的程序员,十分优秀!