MPMoviePlayerController fullscreen not working - objective-c

My code plays the video properly but not in full screen.
-----------
|_______ |
|XXXXXXX| |
|XXXXXXX| |
-----------
Its size is about the size of the X filed area.
I am running this on an ipad2.
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"movie.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoPlayer];
[self.view addSubview:videoPlayer.view];
[videoPlayer setFullscreen:YES];
videoPlayer.view.frame = [[UIScreen mainScreen] bounds];
[videoPlayer play];
[super viewDidLoad];

Set the frame of your MPMoviePlayerController to 1024x768.
videoPlayer.view.frame = CGRectMake(0,0,1024,768); //748 if you have status bar.
Hope this is what you were looking for.
*edit: Try this way, it's the one I use.
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:tempView];
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"www.orangebob.com/files/movie.mp4"]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
playerViewController.view.frame = CGRectMake(0, 0, 1024, 768);
[tempView addSubview:playerViewController.view]; //This *fixes* it, but it's kinda dirty.
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];

Related

MPMovieController control bar not responding

I'm making an iPad version of an app I've already made for iPhone, which means I know this code has worked. I am using self.bounds instead of a static value, so the size to is accordig to the docs.
The thing is: When I open a video, everything shows up as it should. However, I can't press anything on the control bar.
I can't find anobody having this problem either on google or on here...
Anyone got any idea of what the problem might be?
Tom
Code:
mediaController = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
NSLog(#"%#", [[NSNotificationCenter defaultCenter] observationInfo]);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackIsReady:)
name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
object:mediaController];
CGRect rect = self.view.bounds;
//mView = [[UIView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - 30)];
//mView.backgroundColor = [UIColor clearColor];
[mediaController.view setFrame:rect];
[self.view addSubview:mediaController.view];
//[self.view addSubview:mView];
hud = [[MBProgressHUD alloc] initWithView:self.view];
hud.labelText = #"Loading video...";
[self.view addSubview:hud];
[hud show:YES];
[mediaController prepareToPlay];
mediaController.shouldAutoplay = NO;
mediaController.controlStyle = MPMovieControlStyleDefault;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap)];
tapRecognizer.delegate = self;
//[self.view addGestureRecognizer:tapRecognizer];
[mediaController.view addGestureRecognizer:tapRecognizer];

disable user interaction in MPMoviePlayerController

I need to disable total user interaction during a play of a litle video, i already tried to set the style of the control to none : MPMovieControlStyleNone, and put a UIView above the MPMoviePlayerController, but when i pinch the video disappears, and the sound still playing, like i dismissed the video, but it still playing on the background, plus the user interaction is disabled.
Heres how i do:
-(IBAction)startGame:(id)sender
{
NSURL * url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Teste" ofType:#"m4v"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
mBlankView = [[UIView alloc] initWithFrame:moviePlayer.view.frame];
mBlankView.userInteractionEnabled = NO;
[mBlankView setMultipleTouchEnabled:NO];
[mBlankView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:mBlankView];
}
To disable Movieplayer control completely u need to disable your movieplayers view userinteraction as follows:
moviePlayer.view.userInteractionEnabled = NO;

How to play a movie fullscreen using MPMoviePlayerViewController on a view that is being called modally

In a view I have this code to play a movie fullscreen:
NSURL *movieURL = [NSURL URLWithString:#"http://stream.qtv.apple.com/events/jan/1201oihbafvpihboijhpihbasdouhbasv/12pibasvpqihbsdfvihbasdv01_iphone_vod_ref.mov"];
self.mpc = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
NSLog(#"self mpc: %#", self.mpc);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mpc ];
self.mpc.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
self.mpc.moviePlayer.shouldAutoplay = YES;
self.mpc.view.frame = self.view.frame;
[self.view addSubview:self.mpc.view];
self.mpc.moviePlayer.fullscreen = YES;
[self.mpc.moviePlayer play];
The view itself is being called with this code
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
bundle: nil];
TestViewController *controller = [mainStoryboard
instantiateViewControllerWithIdentifier: #"testController"];
[self presentModalViewController:controller animated:YES];
The movie is playing ok, but on the top there is some room the MPMoviePlayerViewController isn't using.
Here's a screenshot showing the problem: https://www.dropbox.com/s/1dje2ar6ynk6855/IMG_2447.PNG
(I've made the background of the testController view yellow)
How can this movie be played fullscreen?
Maybe try something like this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.center = CGPointMake(self.view.center.x, self.view.center.y-100);
[UIView commitAnimations];
If that doesn't work, try not using a modal view controller.
Try to present the video in another modal, something like:
I didn't test this code, but I think it can solve your problem, because probably the problem that you are presenting is because of the previous modal.
NSURL *movieURL = [NSURL URLWithString:#"http://stream.qtv.apple.com/events/jan/1201oihbafvpihboijhpihbasdouhbasv/12pibasvpqihbsdfvihbasdv01_iphone_vod_ref.mov"];
self.mpc = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
NSLog(#"self mpc: %#", self.mpc);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mpc ];
self.mpc.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
self.mpc.moviePlayer.shouldAutoplay = YES;
self.mpc.view.frame = self.view.frame;
[self presentModalViewController:self.mpc animated:NO];
self.mpc.moviePlayer.fullscreen = YES;
[self.mpc.moviePlayer play];

MPMoviePlayerViewController frame size

I have this method:
-(void) playMov: (NSString*) title{
// play a movie!!
NSString *movpath = [[NSBundle mainBundle] pathForResource:title ofType:#"mp4"];
self.mpviewController =[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:movpath]];
[self.mpviewController.view setFrame: CGRectMake(0, 0, self.view.frame.size.width, 275)];
self.mpviewController.view.backgroundColor = [UIColor clearColor];
[self.mpviewController.view setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:mpviewController.view];
MPMoviePlayerController *mp = [mpviewController moviePlayer];
mp.contentURL = [NSURL fileURLWithPath:movpath];
CGRect playerFrame = CGRectMake(0, 0, self.view.frame.size.width, 275);
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mp];
[mp.view setFrame:playerFrame];
mp.view.backgroundColor = [UIColor clearColor];
[mp prepareToPlay];
[[mpviewController moviePlayer] play];
}
The first time the view is loaded - it's full screen with black background.
After the first time is on the wanted size (0, 0, self.view.frame.size.width, 275) still black background.
I want it to be this size and clear background color every time.
Any ideas??
Try using the backgroundView property of the MPMoviePlayerController class.

MPMoviePlayerController controls when opened in a UIModalPresentationFormSheet style modal and the user makes the video fullscreen

In my iPad app, I have a UIButton that is calling an IBAction to call a view controller as a modal to show a video in. I wanted the modal to appear as 720x405, and that part seems to work out okay. Here is the IBAction code the button is executing:
-(IBAction)videoPlayerTest:(id)sender {
VideoModalViewController *vc = [[VideoModalViewController alloc] initWithNibName: #"VideoModalViewController" bundle: nil];
vc.fileName = #"testvideo.m4v";
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated: YES];
vc.view.superview.frame = CGRectMake(0, 0, 720, 405);
vc.view.superview.center = self.view.center;
[vc release];
}
The modal comes up where I want it, and the controls respond on the MPMoviePlayerController; the jog bar, pause, play, etc. but if the user taps on the fullscreen button, the video does go fullscreen alright, but after that the MPMoviePlayerController won't respond to any subsequent taps on the player controls. If I remove the modalPresentationStyle line it will work, but the modal appears on a fullscreen view instead of the 720x405 modal like I want. I've added Observers to try resizing the frame and recenter it when the user makes the movie controller fullscreen and back to windowed, but it didn't appear to help at all. Here is that code.
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(#"willEnterFullscreen");
[self setModalPresentationStyle:UIModalPresentationFullScreen];
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.view.center = self.view.center;
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(#"willExitFullscreen");
[self setModalPresentationStyle:UIModalPresentationFormSheet];
self.view.frame = CGRectMake(0, 0, 720, 405);
self.view.center = self.view.center;
}
- (void)playMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 720, 405);
moviePlayer.view.backgroundColor = [UIColor grayColor];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
This is my first post-- hope I did it right and provided enough information about the problem I'm having.
I've solved my problem. I was unaware of MPMoviePlayerViewController and I created that and used that as my modal instead. It works great.
-(void)playVideo:(NSString *)fileName {
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentModalViewController:mpViewController animated:NO];
[[mpViewController moviePlayer] play];
}
-(IBAction)videoPlayerTest:(id)sender {
[self playVideo:#"testvideo.m4v"];
}
Thought I'd post what I came up with just in case somebody else encounters the same