关于AVPlayerItem对象的属性duration返回播放总时长的坑

最近在使用AVPlayer播放网络流媒体,发现一个坑:

就是playerItem.duration有可能不返回该网络多媒体资源的播放总时间长度,而是返回了一个奇怪的数据:nan,

因为我通过CMTimeGetSeconds(playerItem.duration)得到的一直是nan,

而几经周折费劲,发现CMTimeGetSeconds(playerItem.asset.duration)返回的却是该网络多媒体资源的正确的播放总时间长度.

这大概可能是AVPlayerItem类的一个bug,

在改成通过playerItem.asset.duration获取网络多媒体资源的播放总时间长度之后,就再也没有出现播放总时间长度为nan的情况了.

 

原文地址:https://www.cnblogs.com/hello-Huashan/p/5143498.html