当媒体片段数量较少时,AVPlayer 是否播放视频块

does AVPlayer play the video chunk when number of media segments are less

我不确定这一点 - 当 AVPlayer 收到没有足够媒体片段的播放列表文件时(例如播放列表中只有 1 或 2 个媒体片段,如下所示)。并根据 Apple 设备文档的 HLS 创作规范

>7.媒体分割要求

7.6. Segment durations SHOULD be nominally 6 seconds (e.g., NTSC 29.97 may be 6.006 seconds).

7.7. Media segments MUST NOT exceed the target duration by more than 0.5 seconds.

下面是我的 VOD 示例播放列表文件

#EXTM3U
   #EXT-X-VERSION:4
   #EXT-X-TARGETDURATION:2
   #EXT-X-MEDIA-SEQUENCE:56
   #EXT-X-ALLOW-CACHE:NO
   #EXT-X-DISCONTINUITY
   #EXTINF:2.009,
   http://media.example.com/first.ts

   #EXTM3U
   #EXT-X-VERSION:4
   #EXT-X-TARGETDURATION:2
   #EXT-X-MEDIA-SEQUENCE:56
   #EXT-X-ALLOW-CACHE:NO
   #EXT-X-DISCONTINUITY
   #EXTINF:2.003,
   http://media.example.com/Second.ts

   #EXTM3U
   #EXT-X-VERSION:4
   #EXT-X-TARGETDURATION:2
   #EXT-X-MEDIA-SEQUENCE:56
   #EXT-X-ALLOW-CACHE:NO
   #EXT-X-DISCONTINUITY
   #EXTINF:2.003,
   http://media.example.com/third.ts

+++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++

   #EXTM3U
   #EXT-X-VERSION:4
   #EXT-X-TARGETDURATION:2
   #EXT-X-MEDIA-SEQUENCE:56
   #EXT-X-ALLOW-CACHE:NO
   #EXT-X-DISCONTINUITY
   #EXTINF:2.004,
   http://media.example.com/first.ts
   #EXTINF:2.007,
   http://media.example.com/second.ts
   #EXTINF:2.003,

============================================= =========

   #EXTM3U
   #EXT-X-VERSION:4
   #EXT-X-TARGETDURATION:2
   #EXT-X-MEDIA-SEQUENCE:56
   #EXT-X-ALLOW-CACHE:NO
   #EXT-X-DISCONTINUITY
   #EXTINF:2.009,
   http://media.example.com/first.ts
   #EXTINF:2.008,
   http://media.example.com/second.ts
   #EXTINF:2.003,

所以我的问题是 - AVPlayer 是否仅在所有 3 个媒体片段可用时播放内容,或者即使在 1 或 2 个媒体片段可用时也会播放内容,如上所示??

是的.. AVPlayer 将播放包含一个或多个视频块的播放列表或 .ts packet.I 在我这边尝试过.. 通过在播放列表文件中使用 2 秒的视频块并且它确实有效。下面是用于测试的示例代码。

let urlStr = URL(string: "http://100.177.1.101/jumpingBunny.m3u8")

let asset = AVAsset(url: (urlStr ?? nil)!)
let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: playerItem)

var playerLayer: AVPlayerLayer?
playerLayer = AVPlayerLayer(player: player)
playerLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
playerLayer!.frame = self.view.frame
self.view!.layer.addSublayer(playerLayer!)

let playerViewController = AVPlayerViewController()
playerViewController.player = player
playerViewController.showsPlaybackControls = true

player.play()