MPMoviePlayerController video does not fill up the entire view - iphone

I am trying to add a MPMoviePlayerController view to my app. I am trying to control the position of it in code, and then place my own buttons underneath it (just a fullscreen and play/pause button).
However, the video does not take up the entire area of the video player. Is this normal? Can I make it so the entire thing is video? (This is what I mean: http://i.imgur.com/GWHlD8V.png)
This is how I am implementing it:
in .h:
#interface ViewController : UIViewController
#property (nonatomic, strong) MPMoviePlayerController *moviePlayerController;
#end
in .m:
NSURL *url = [NSURL URLWithString:#"http://localhost:8013/prog_index.m3u8"];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
_moviePlayerController.controlStyle = MPMovieControlStyleNone;
// This places the player exactly where I want it. When I want it full screen
// I can dynamically update these values?
[_moviePlayerController.view setFrame:CGRectMake(100, 181, 650, 500)];
_moviePlayerController.view.layer.borderColor = [UIColor colorWithRed:0.329 green:0.80 blue:0.227 alpha:1].CGColor;
_moviePlayerController.view.layer.borderWidth = 2.0;
_moviePlayerController.shouldAutoplay = YES;
[self.view addSubview:_moviePlayerController.view];
[_moviePlayerController play];
Everything seems to work fine, except there are those black bars above and below the video. I would like it to be just possible, and replace the bottom one with my custom controls. Any thoughts?
Also, is this the best way to position the player?

Related

How to rotate a video 90º in MPMovieplayercontroller

I am using MPMovieplayercontroller to play video it plays the video which comes from web services. Source video file was taken in potrait mode but it has been rotated 90º in anti-clockwise direction. So when i am playing it in MPMovieplayercontroller it is playing like following format attached is the sample image
Is there any way to rotate the video file which comes from web service?
I have tried to apply transform for MPMovieplayercontroller.view but movie player controls also rotating. my requirement is i would need to rotate the video part only. Is there any way to achieve this. Please help me out to fix this it would be great help.
Thanks in advance
try with this: (I have made a subclass for MPMoviePlayerViewController)
- (void)configureSubViews
{
if (self.moviePlayer.view.subviews.count > 0)
{
UIView *view = self.moviePlayer.view.subviews[0];
if (view.subviews.count > 0)
{
UIView *sView = view.subviews[0];
self.viewPlayerVideoContent = [sView viewWithTag:1002];
self.viewPlayerControls = [sView viewWithTag:1003];
}
}
}
I don't really like to work in that way with the subViews, but it works.. (at least for iOS5 and iOS6)
then, you could try to rotate the viewPlayersVideoContent :)
You need to rotate MPMoviePlayer view as per the following code.
This will work best. I have tested it.
NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Video" ofType:#"mp4"]];
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
[moviePlayerController.moviePlayer prepareToPlay];
[moviePlayerController.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
[moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:moviePlayerController.view];
You may achieve this by following code,
yourMoviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
and if you want to keep you controls at some place fixed, by default its not possible. So you need to hide the default controls by following code,
yourMoviePlayerController.controlStyle = MPMovieControlModeHidden;
and then add a subView for the controls programatically.

How can i add a video as a HUD element in iphone sdk

I want to add a video that shows up when i call it but not a typical (stretch-to-bounds) view
similar to the ProgressHud view that loads in the middle and darkens the background. how can I load a video say from LBYoutubeController or natively?
Thanks!
edit: ideally the video box will take up 60-70 % of the screen but again will be centered and overshadowing the background
You need to use a MPMoviePlayerController. You can set the controlStyle to MPMovieControlStyleEmbedded and this will give you a player with no controls. Set the scalingMode to MPMovieScalingModeFill to make the video conform to the frame you set for it regardless of the video's natural layout. Just add the movie player's view to your view hierarchy and you're good to go.
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.scalingMode = MPMovieScalingModeFill;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[myView addSubview:moviePlayer.view];
To add a dimming view behind this:
UIView *back = [[UIView alloc]initWithFrame:myView.bounds];
back.backgroundColor = UIColor.blackColor;
back.alpha = 0.7;
[myView insertSubview:back belowSubview:myView];

iOS - entire View shifts up after rotation

Doing a very simple iPad app that plays a video in fullscreen. I want the video perfectly centered, but on initial load it's a bit too far down. When I rotate it, the view resets itself properly to be perfectly centered. Obviously I'd love to have it look this way from the start.
Here's my code in viewDidLoad:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"movie" ofType:#"m4v"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer prepareToPlay];
CGRect screenBounds = [UIScreen mainScreen].bounds;
[moviePlayer.view setFrame:CGRectMake(0, 0, screenBounds.size.height, screenBounds.size.width)];
[self.view addSubview:moviePlayer.view];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer play];
[super viewDidLoad];
The app is set to only show in landscape mode, so the rotation takes effect every 180 degrees (instead of 90). BTW the moviePlayer var is set in the .h file like so:
#property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
Then it's synthesized in my ViewController:
#synthesize moviePlayer;
So does anyone have any ideas? I tried changing "setFrame" to start at 0,-20 instead of 0,0 but that messed things up on the later rotations. If there's a way to ignore the dumb status bar on initial load, I'd love to know it. Thanks.
Try setting the frame in -viewDidLayoutSubviews. Layout should be handled there, not in the setup methods.
Try calling
[self setWantsFullScreenLayout:YES];
in the viewcontroller implementation. This should force it to "ignore the dumb status bar on initial load".

MPMoviePlayerController visible while loading stream

Any one know how to keep the MPMoviePlayerController visible while the movie is loading.
Or before the movie is ready to play?
For some reason it only shows up when the Movie is ready to play.
Heres what I have.
mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:[mp view]];
mp.view.frame = mediaPlayerContainer.frame;
[mediaPlayerContainer removeFromSuperview];
mp.useApplicationAudioSession = YES;
mp.shouldAutoplay = YES;
mp.controlStyle = MPMovieControlStyleFullscreen;
My mediaPlayerContainer is just a dummy container so I can visually build a frame for my mp view.
The only other thing I can think of doing is using a "screenshot" of a player as a place holder. And removing it if the player is in "play" mode.
That seems janky though.
Thnks.
MPMoviePlayerController has a backgroundView property...
You can add an UIImageView to it and it should be displayed while it is loading the video.

Hide MPMoviePlayerController while new video loads

I have an iPad app that has 4 buttons on the left side that corresponds to 4 different video clips. When a user taps the video they want to see, it appears on the right side. I am wanting it to appear to be loading (as if it were streaming over the internet). I added the UIActivityIndicator to the center of the black video frame and have a thread that pauses for 3 seconds. However, the player containing the previous video does not disappear. It just freezes on the last frame of the previous video for 3 seconds (hiding the activity indicator) and then the new video appears.
Any ideas on how to make the player temporarily be hidden? Thanks for any help. Here is my code:
-(IBAction) videoButton1{
[player stop];
[player release];
[self.activityIndicator startAnimating];
NSString *url = [[NSBundle mainBundle] pathForResource:#"video1" ofType:#"mov"];
[self setupVideoPlayer:url];
}
-(void) setupVideoPlayer: (NSString *) url{
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url)];
player.view.frame = CGRectMake(487, 205, 478, 320);
[self.view addSubview:player.view];
[NSThread sleepForTimeInterval:3.0];
self.activityIndicator stopAnimating];
[player play];
}
You can set the frame of your player to a View that you can make in IB or programmatically instead of doing a CGRectMake every time.
self.player.view.frame =
self.viewForMovie.bounds;
self.player.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
Then in your "videoButton1" you can set the alpha of the View to 0
viewForMovie.alpha = 0;
And in your "setupVideoPlayer" you can change the alpha back to 1.