Reputation: 12184
I have a MPMoviePlayerController playing a video.
My problem is that, video's dimensions change to maintain the aspect ratio and hence many time there is a big black gap between the video's boundaries and that of the Player. The black gap is horizontal and vertical.
Is there a way I can get to know what is the rectangle the actual video is contained in? Then I could find out the touch coordinates with respect to that of the video.
Upvotes: 3
Views: 1818
Reputation: 27597
To get the proper dimensions / aspect ratio of the movie content, you can use the MPMoviePlayerController
property naturalSize
.
From the MPMoviePlayerController Class Reference
naturalSize
The width and height of the movie frame. (read-only)
@property (nonatomic, readonly) CGSize naturalSize
Discussion
This property reports the clean aperture of the video in square pixels. Thus, the reported dimensions take into account anamorphic content and aperture modes.
It is possible for the natural size of a movie to change during playback. This typically happens when the bit-rate of streaming content changes or when playback toggles between audio-only and a combination of audio and video.
Availability Available in iOS 3.2 and later. Declared In MPMoviePlayerController.h
Now lets assume you are playing a movie that returns 280x150
for its natural size. That results into an aspect ration of roughly 1.87
(width divided by height). Now let us assume you have a screen resolution of 768x1024 (iPad, portrait). If now you wanted to display that movie in the most screen filling way but still keep some of your controls visible, you would use the following calculation for the actual MPMoviePlayerController.view
height:
768 / 1.87 = 411
(rounded)
The resulting frame is:
MPMoviePlayerController.view.frame = CGRectMake(0.0f,
(1024.0f - 411.0f) / 2.0f,
768.0f,
411.0f);
Upvotes: 5