Sunday, 8 September 2013

iOS MPMovePlayerController Sizing

iOS MPMovePlayerController Sizing

I need to be able to play a short video stored on the iPad device in a
frame with w x h of 400x236. So, far so good -- I'm using the
MPMoviePlayerController. However, this view must "slide" in from the top
of the screen, so that behaves similar to other controls (in particular, a
webview-based player for youtube videos).
I've made a UIView subclass and in the init I have the following code:
NSURL *url = [NSURL URLWithString:videoID];
MPMoviePlayerController *player;
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[player.view setFrame: self.bounds];
[self addSubview: player.view];
[self bringSubviewToFront:player.view];
player.movieSourceType = MPMovieSourceTypeFile;
[player setScalingMode:MPMovieScalingModeFill];
[player prepareToPlay];
[player play];
The video plays perfectly. However, when the player is init-ed, it is for
a fraction of a second full screen, during which it "flies" into my UIView
(represented by the subclass) which is framed the correct size; so in less
than a second it goes from full screen to properly scaled to fit in the
UIView's bounds, which of course is too distracting to use in the app.
What I need is for it to be the size of view's bounds when the user first
sees it, but it appears that what I'm getting is a full-screen view that
quickly animates down to the correct size. From there, everything works
fine.
player.view is readonly, so I can't set it's view hidden until it is added
to the UIView.
My question is this: Is there anyway to hide the MPMoviePlayerController
instance until it resizes to its parent UIView, or otherwise make it scale
to the correct size BEFORE the user sees it?
TIA for any suggestions.

No comments:

Post a Comment