AVURLAsset getting video size

前端 未结 7 1872
礼貌的吻别
礼貌的吻别 2020-12-03 16:57

This is pretty frustrating. I\'m trying to get the size of an AVURLasset, but try to avoid naturalSize since Xcode tells me, this is deprecated in iOS5.

<
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 17:17

    The deprecation warning on the official documentation suggests, "Use the naturalSize and preferredTransform, as appropriate, of the asset’s video tracks instead (see also tracksWithMediaType:)."

    I changed my code from:

    CGSize size = [movieAsset naturalSize];
    

    to

    CGSize size = [[[movieAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize];
    

    It's less pretty and less safe now but won't break when they drop that method.

提交回复
热议问题