Francisco Gutiérrez
Francisco Gutiérrez

Reputation: 1393

iOS 6: AVPlayerItem PresentationSize returning zero - (naturalSize method Deprecated on iOS 5)

Got this code:

videoSize = [[AVPlayerItem playerItemWithAsset:asset] presentationSize]; 

// nslogs -> height: 000 width 000

And this deprecated:

videoSize = [asset naturalSize];

// nslogs -> height: 360 width 480

Why is this happening? I don't get it.

Upvotes: 3

Views: 2420

Answers (2)

RY_ Zheng
RY_ Zheng

Reputation: 3427

  1. The presentationSize in AVPlayerItem may return a value of CGSizeZero when the player item is not ready to paly.doc
  2. The naturalSize in AVAsset is depressed. doc
  3. Just like your code, it is recommended to use naturalSize and preferredTransform in AVAssetTrack.
CGSize size = [[[movieAsset tracksWithMediaType:AVMediaTypeVideo] firstObject] naturalSize];

Upvotes: 0

Francisco Gutiérrez
Francisco Gutiérrez

Reputation: 1393

Solved:

NSArray* allVideoTracks = [movieAsset tracksWithMediaType:AVMediaTypeVideo];
if ([allVideoTracks count] > 0) {
AVAssetTrack* track = [[movieAsset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0];
CGSize size = [track naturalSize];
}

this made my day, hope it works for someone else...

Upvotes: 10

Related Questions