iosobjective-cuiviewmpmovieplayer

MPMoviePlayerController not in UIView


I am trying to add a MPMoviePlayerController to a UIView.

I am doing it, but it is appearing at the top of my view instead of the position the UIView has in my storyboard.

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.frame = videoView.bounds;
moviePlayer.scalingMode = MPMovieScalingModeFill;
moviePlayer.scalingMode = UIViewContentModeScaleAspectFit;
moviePlayer.repeatMode = MPMovieRepeatModeOne;
[self.view addSubview:moviePlayer.view];

Any ideas?


Solution

  • Change [self.view addSubview:moviePlayer.view]; to [videoView addSubview:moviePlayer.view];

    If you want your moviePlayer to be at the position of your UIView, you have to add it as a subview to that particular UIView. If you add your moviePlayer to self.view it will be added on top of every other subview.

    EDIT: If you want to add the moviePlayer as a subview to your main view, then change moviePlayer.view.frame = videoView.bounds; to moviePlayer.view.frame = videoView.frame;