Reputation: 430
I'm not sure on this - when AVPlayer receives the Playlist file which does not have sufficient media segments (like only 1 or 2 media segments only there in playlist as shown below). And as per As per the HLS Authoring Specification for Apple Devices document
> 7. Media segmentation requirements
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.
Below are my sample playlist file for 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,
So my question is - will AVPlayer play content only when all 3 media segments available or will play even when 1 or 2 media segments available as shown above ??
Upvotes: 3
Views: 1147
Reputation: 1910
Yes.. AVPlayer will play the playlist which has one or more video chunk or .ts packet.I did try at my end.. by using video chunk of 2 seconds in playlist file and it did work. Below is sample code used for testing.
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()
Upvotes: 2