SJVideoPlayer
SJVideoPlayer copied to clipboard
m3u8加载速度慢
首先很感谢作者的强大播放器!
问题:在使用的过程中,产品反馈视频加载速度慢,经过对比 ZFPlayer
,确实存在此问题,对比效果如下视频所示,大视频区域是 SJVideoPlayer
,小视频区域是 ZFPlayer
,同时加载 m3u8
链接,SJVideoPlayer
会慢一些。
希望作者能看下如何解决该问题,感谢!
https://user-images.githubusercontent.com/19367531/153390752-c8f2f7ff-8419-45f9-8896-deb6878d17cb.mov
m3u8
链接:
https://video.591.com.tw/debug/target/house/hls/2021-07-14/130/stream_1.m3u8
试试把AVPlayer的这个属性automaticallyWaitsToMinimizeStalling
设置成NO看看:
NSURL *url = [NSURL URLWithString:@""];
AVPlayer *avp = [AVPlayer.alloc initWithURL:url];
avp.automaticallyWaitsToMinimizeStalling = NO;
SJVideoPlayerURLAsset *asset = [SJVideoPlayerURLAsset.alloc initWithAVPlayer:avp];
_player.URLAsset = asset;
试了,还是一样慢
代码如下:
let avp = AVPlayer(url: url)
avp.automaticallyWaitsToMinimizeStalling = false
self.player.urlAsset = SJVideoPlayerURLAsset(avPlayer: avp)
还有这个. 设置0秒, 不延迟隐藏占位图
_player.delayInSecondsForHiddenPlaceholderImageView = 0;
👍 相比之前确实快了很多,不过相对于右边的还是有一丢丢慢(有使用 automaticallyWaitsToMinimizeStalling = false
)
设置 self.player.delayInSecondsForHiddenPlaceholderImageView = 0
后的效果:
https://user-images.githubusercontent.com/19367531/153521906-3debc3e2-2ca7-4efd-ad82-49ef5a688de7.mov
这是视觉上的慢,占位图隐藏&视频显示动画导致的,相关源码如下:
BOOL animated = _URLAsset.original == nil;
[self.presentView hiddenPlaceholderAnimated:animated delay:delay];
根据上述源码,对现有代码做了如下调整:
let avp = AVPlayer(url: url)
avp.automaticallyWaitsToMinimizeStalling = false
guard let urlAsset = SJVideoPlayerURLAsset(avPlayer: avp) else { return }
self.player.urlAsset = SJVideoPlayerURLAsset(otherAsset: urlAsset, playModel: nil)
这样可以很快将视频展示出来,效果如下:
https://user-images.githubusercontent.com/19367531/153526190-836998da-4991-4c04-bb27-a3e9738bd77d.mov
不过还是希望作者能提供属性可以强行控制是否需要执行动画 😁
好滴