滚动滚动时,Avplayer项目在uitableview上进行缓冲
我已经创建了一个使用自定义的ViewCells的UitableView。 UitaiteView由通过Internet加载的图像和视频组成。当用户滚动时,在一个uitaiteviewcell中滚动时,我加载了avplayer来播放HLS视频。我以HLS格式将URL设置为Avplayer项目以播放该项目。
self.playerController = [[AVPlayerViewController alloc] init];
NSURL *videoURL = @"https://playeritemvideourl";
self.player = [AVPlayer playerWithURL:url];
self.playerController.player = self.player;
[self.player play];
视频播放,但从[self.player play]
触发的时刻延迟约3到5秒。如何将视频放在avplayer的CurrentItem上,因此当我滚动到特定的uitableviewcell时,视频开始播放?我查看了avplayeritem上的 preferredforwardbufferduration 属性,但似乎没有任何区别。任何帮助或建议都感谢!
I have created an UITableView with custom UITableViewCells. UITableView consists of images and videos that load via internet. While user is scrolling in one of the UITableViewCell i load AVPlayer to play a hls video. I set URL in hls format to the avplayer item in order to play the item.
self.playerController = [[AVPlayerViewController alloc] init];
NSURL *videoURL = @"https://playeritemvideourl";
self.player = [AVPlayer playerWithURL:url];
self.playerController.player = self.player;
[self.player play];
The video plays but there is a delay of about 3 to 5 seconds from the moment [self.player play]
is triggered. How do i pre buffer the video to the currentitem of avplayer so when i scroll to the specific UITableViewCell the video starts playing instantly? I looked at preferredForwardBufferDuration
property on AVPlayerItem but does not seem to make any difference. Any help or suggestions appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
avplayer
在实例化时开始流M3U8。 (我通过监视Xcode的调试导航器中的网络图来注意到这一点。我在不调用的情况下实例化了Avplayer,而网络正在加载。)而不是加载
avplayer < /code>一旦单元格变得可见,实例化
avplayer
play content < em>当它变为可见时。可以通过首先让一些数据结构保存
avplayer
项目来实现这一点。我会推荐一个nsmutabledictionary
,因为我们可以设置您想要的视频URL的键,并且该对象可以是已加载带有URL的avplayer
。有两种填充结构的方法。您可以在-viewDidload
之类的方法中立即加载所有内容,也可以在-scrollviewDidsCroll中动态加载项目:
确定我们是否靠近带有视频的单元格。如果没有很多内容,我会使用前者,并且用户几乎可以保证观看所有视频。如果我们有很多内容可以加载,或者用户可能无法观看所有视频,我将使用后者。这是一个带有uitaiteViewController
的示例。mytableViewController.h
mytableViewController.m
这与您提供的代码和信息的数量一样具体。希望这有帮助!
AVPlayer
begins streaming m3u8 when it is instantiated. (I noticed this by monitoring the Network graph in the Debug navigator in Xcode. I instantiated an AVPlayer without calling-[play]
and the network was under load.) Instead of loading theAVPlayer
once the cell becomes visible, instantiate theAVPlayer
before the cell is visible and play the content when it becomes visible.This can be implemented by first having some data structure hold the
AVPlayer
items. I would recommend aNSMutableDictionary
, as we can set the key to the video's URL we want and the object can be theAVPlayer
already loaded with the URL. There are two ways to populate the structure. You could load it all at once in a method like-viewDidLoad
or load items in dynamically in-scrollViewDidScroll:
to determine if we are close to a cell with a video. I would use the former if there is not a lot of content and the user is almost guaranteed to watch all the videos. I would use the latter if we have a lot of content to load or if the user might not watch all the videos. Here is an example with aUITableViewController
.MyTableViewController.h
MyTableViewController.m
This is about as specific as I can make with the amount of code and information you provided. Hope this helps!