AVPlayerStatus vs AVPlayerItemStatus

99封情书 提交于 2019-12-10 14:09:06

问题


The issue is that player.status returns AVPlayerStatusReadyToPlay a full 2 seconds before player.currentItem.status returns AVPlayerItemStatusReadyToPlay. Does anyone have any helpful explanations as to why this is happening?
This is just sample code to show the basic idea of what's happening so if there are any typos or whatever please ignore them.

- (void) someMethod
{    
    player = [[AVPlayer alloc] initWithURL:someValidURL];
    [player play];

    NSTimer *timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(checkStatus:) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}

- (void) checkStatus: (NSTimer *)timer
{
    NSLog(@"player status: %i", player.status]);
    NSLog(@"player item status: %i", player.currentItem.status]);
}

回答1:


In our experience building Ultravisual the AVPlayerStatus and AVPlayerItemStatus are only kind of related to each other, and often depend on async states -- ie, the implementations tend to be heavily multithreaded, and are often buggy or poorly defined.

We found AVPlayerItemStatus to be the most reliable indicator of actually really ready to play, but there were some gotchas especially when dealing with AVQueuePlayer or AVPlayerItems built from AVMutableComposition instances.



来源:https://stackoverflow.com/questions/6111005/avplayerstatus-vs-avplayeritemstatus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!