1

I need to know if the video I am playing from the web through AVURLAsset is portrait or landscape.

In the past I have done this with local videos by getting the video track's natural size, applying its preferred transform, and then comparing width and height. Example:

if let assetTrack = asset.tracks(withMediaType: AVMediaType.video).first {
    let temp = assetTrack.naturalSize.applying(assetTrack.preferredTransform)
    let size = CGSize(width:fabs(temp.width), height: fabs(temp.height))
    return size.height > size.width
}

But for this streamed video, asset.tracks is empty, so I can't check the natural size.

Does anyone know how to resolve this?

Jake G
  • 1,185
  • 9
  • 19
  • Try `[asset tracksWithMediaCharacteristic:AVMediaCharacteristicVisual]]` and get its natural size? Are all tracks empty? Never ever had that before.. – Brandon Feb 01 '18 at 01:09
  • Unfortunately no luck with `tracksWithMediaCharacteristic` because yeah, the whole tracks array is empty. Thanks for the suggestion though! – Jake G Feb 01 '18 at 17:58

1 Answers1

1

After playing around with it all day, I was able to find the solution:

Apparently streaming a .m3u8 HLS file will always result in an empty asset.tracks array.

The way to get the dimensions is through the AVPlayerItem.presentationSize property.

Jake G
  • 1,185
  • 9
  • 19