AVPlayer is not ReadyForDisplay, 不显示
我无法理解在什么条件下 AVPlayer readyForDisplay 对于本地存储的视频剪辑将是“YES”。我正在构建一个应用程序,其主视图有两个子视图,每个子视图都是 UIView 的自定义子类,其中包含一个 AVPlayer 和一个用于显示视频的 APPlayerLayer 。应用程序响应用户输入在显示这两个子视图之间切换。在我的主视图控制器中,我有这样的内容:
- (void)viewDidLoad
{
firstView = [VideoView alloc] initWithFileName:@"clip1.mov"]]; // VideoViews are assigend to instance variables
secondView = [VideoView alloc] initWithFileName:@"clip2.mov"]];
[[self view] addSubview:firstView];
}
这些视图的初始化加载 AVPlayer 并创建一个 AVPlayerLayer。启动应用程序时,第一个剪辑会正确显示。为了响应用户输入,第二个视频将显示在第一个视频的位置,如下所示:
- (void)responseToEvent
{
NSLog(@"%i", [targetView.readyForDisplay]); // prints out "1" in the console
[firstView removeFromSuperview];
[self.view addSubview:secondView];
}
这工作正常。但是,如果我更改 viewDidLoad 将 secondaryView 放入 NSMutableDictionary 中,如下所示:
- (void)viewDidLoad
{
firstView = [VideoView alloc] initWithFileName:@"clip1.mov"]];
VideoView *secondView = [VideoView alloc] initWithFileName:@"clip2.mov"]];
[someViews setObject: secondView forKey:viewIndex];
[[self view] addSubview: firstView];
}
... 然后稍后从 someViews 中获取视图,如下所示:
- (void)responseToEvent
{
VideoView *secondView = [neighborViews objectForKey:link.targetView.pftViewId];
NSLog(@"%i", [targetView.readyForDisplay]); // prints out "0" in the console
[firstView removeFromSuperview];
[self.view addSubview:secondView];
}
... 这不起作用。没有显示视频。我不明白为什么将包含视图放入 NSMutableDictionary 会导致 AVPlayer 未准备好并且不显示视频。此外,视频永远不会出现(它永远不会变得“准备好”)。有谁知道这是怎么回事?
I'm having trouble understanding under what conditions AVPlayer readyForDisplay would be "YES" for a locally stored video clip. I am building an application whose main view has two subviews, each of which is a custom subclass of UIView that contains an AVPlayer and an APPlayerLayer to display video. The application switches between display these two subviews in response to user input. In my Main view Controller, I have something like this:
- (void)viewDidLoad
{
firstView = [VideoView alloc] initWithFileName:@"clip1.mov"]]; // VideoViews are assigend to instance variables
secondView = [VideoView alloc] initWithFileName:@"clip2.mov"]];
[[self view] addSubview:firstView];
}
The initialization of these views loads up the AVPlayer and creates an AVPlayerLayer. When the app is launched, the first clip is shown correctly. In response to user input, the second video is displayed in place of the first, like so:
- (void)responseToEvent
{
NSLog(@"%i", [targetView.readyForDisplay]); // prints out "1" in the console
[firstView removeFromSuperview];
[self.view addSubview:secondView];
}
This works fine. HOWEVER, if I change the viewDidLoad to put secondView into an NSMutableDictionary like so:
- (void)viewDidLoad
{
firstView = [VideoView alloc] initWithFileName:@"clip1.mov"]];
VideoView *secondView = [VideoView alloc] initWithFileName:@"clip2.mov"]];
[someViews setObject: secondView forKey:viewIndex];
[[self view] addSubview: firstView];
}
... and then later get the view out of someViews like this:
- (void)responseToEvent
{
VideoView *secondView = [neighborViews objectForKey:link.targetView.pftViewId];
NSLog(@"%i", [targetView.readyForDisplay]); // prints out "0" in the console
[firstView removeFromSuperview];
[self.view addSubview:secondView];
}
... this DOES NOT work. There is no video shown. I can not understand why putting the containing view into an NSMutableDictionary would cause the AVPlayer to not be ready and to not display video. Furthermore, the video never appears (it never becomes "ready"). Does anyone know what is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Key值观察者来监听状态的变化:
然后在同一个类中添加:
确保最后删除观察者
Use Key value observers to listen for a change in state:
then in the same class add:
make sure to remove the observer at the end