An1Ba7 An1Ba7 - 1 year ago 131
Objective-C Question

Get the dimensions of video programmatically in objective c

I am a beginner in iOS development. I am developing an application where I require the size of a video which is getting played in the MPMoviePlayerController.

I am using the property naturalSize of MPMoviePlayerController to get the dimensions of the video that is played.

@property(nonatomic, readonly) CGSize naturalSize;

But the problem is that I can get the natural size only when the Video gets played in the MPMoviePlayerController.

Is there a way in which I can get the dimensions of the video before it gets played in the MPMoviePlayerController.

-- EDIT --

Is there any other workaround I can approach to solve this problem? Please help.

sch sch
Answer Source

It takes time for the MPMoviePlayerController to load the video metadata, so you should add a listener and wait for the naturalSize to be loaded. Something like this:

[[NSNotificationCenter defaultCenter] addObserver:self

And in movieNaturalSizeAvailable:, myVideoPlayer.naturalSize gives you the desired value and after that, you can play the video.