MPMoviePlayerViewController not rotating in landscape with tabbar - iphone

I display a video using MPMoviePlayerViewController in a tabbar application, the video plays fine in portrait mode but doesn't rotate in landscape mode.
The same code works fine in another project without the tabbar.
I tried to force the autoresizingmask to flexibleWidth and flexibleHeight without success.
If i return YES in the shouldAutorotateToInterfaceOrientation the status bar rotates but not the movie interface.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
-(IBAction) showFamilleMovie {
NSString *videoURL = [[NSBundle mainBundle]
pathForResource:#"film1"
ofType:#"mp4"];
MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoURL]];
theMoviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];
}
Do you have any idea where the project could come from ?
Thanks,
Vincent

you can try:
[yourTabbarController presentModalViewController: theMoviePlayer]
that should allow MoviePlayer to rotate.

I had the same problem and the code killer for that was a view added in my appDelegate code. It didn't let the player to rotate properly.
My problem was: To implement the FBConnect library, you need to add a view in your appDelegate to get the object for the FB controller class that you're using the handleOpenURL method (back from Safari when auth is done) and control the callback. I spent an hour until I realized that this view was blocking the rotation.
BTW, don't care about the tab bar. The player should rotate correctly even if you don't have the shouldAutorotateToInterfaceOrientation method added.

Related

iOS - Force full screen video

I'm using a MPMoviePlayerViewController. When the video loads and starts playing it doesn't fill up the whole screen. I have to press the full screen button at the top right to make that happen. If I use MPMoviePlayerController I can't get it to fill the screen at all.
Any way via code that I can get my video full screen using the MPMoviePlayerViewController without having to press the fullscreen button?
I know i'm using a private API here, but thats ok, it is for a demo.
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"phatpad" ofType:#"mov"];
if (moviePath)
{
NSURL *url = [NSURL fileURLWithPath:moviePath];
player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
}
player.view.frame = self.view.frame;
[self.view addSubview: player.view];
}
Here is a screen. The first is without pressing the full screen button, the second is after pressing it.
You have to set the fullscreen attribute to true and the scallingMode to the aspect fill like this:
if (moviePath)
{
NSURL *url = [NSURL fileURLWithPath:moviePath];
player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
player.moviePlayer.fullscreen = YES;
player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
}
I have tested at home and it works, so I hope to you too.
On iPhones and iPod Touches, MPMoviePlayerController plays in full screen no matter what, so I'm assuming you're talking about an iPad? Can we please see some code samples? I can make mine full screen simply by resizing the UIView in my XIB file. How are you trying to do it?

UIVideoEditorController breaks MPMoviePlayerViewController?

In my app, I can use code like this to play a video:
- (void)playVideo:(NSURL *)url {
MPMoviePlayerViewController *m = [[[MPMoviePlayerViewController alloc] initWithContentURL:url] autorelease];
[self.rootViewController presentMoviePlayerViewControllerAnimated:m];
}
And it works fine.
But if I use code like this to display a video editor:
- (void)editVideo:(NSString *)file {
UIVideoEditorController *ed = [[[UIVideoEditorController alloc] init] autorelease];
ed.delegate = self;
ed.videoPath = file;
[self.rootViewController presentModalViewController:ed animated:YES];
}
- (void)videoEditorControllerDidCancel:(UIVideoEditorController *)vc {
[vc.parentViewController dismissModalViewControllerAnimated:YES];
}
and just hit cancel, the playVideo: method will no longer play a video! It brings up the movie player window fine and does the throbber to indicate loading, but once the load finishes it fails. Sometimes it closes the video window right away without playing anything, and sometimes it changes to a black screen that responds to no input (but will go away if I send the app to the background and then bring it back to the foreground). It's not MPMoviePlayerViewController Black Screen issue! though, as I get the same black screen if I intentionally leak the MPMoviePlayerViewController.
Am I doing something wrong, or is Apple's junk just broken?

iphone MediaPlayerController does not show the media player

HI,
I am developing an app which contains 3 tab view control. One each for audio, video and images.
When i select the video tab, I have all the items displayed in the table view format so that on selection of any cell, the video is shown.
Example.
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]] ;
[moviePlayer play];
}
The problem with this is though I am able to play the video I am unable to see the video and can hear only the audio.
In addition, if I were to close the app while the video is playing, and start it the app, the application crashes.
Can you please let me know how should I go ahead ?
After spending some more time, I have found out that for version above 3.2 one has to use MPMoviePlayerViewController.
The use of the same resolved the issue.
if ([[[UIDevice currentDevice] systemVersion ] doubleValue] >= 3.2) {
MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:urlAddress]];
if (mediaPlayer) {
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile ;
[mediaPlayer.moviePlayer play];
[mediaPlayer release];
}
}
Check out this technote from Apple:
http://developer.apple.com/library/ios/#qa/qa2010/qa1240.html
To summarize, you need to add the movie player controller's view as a subview of your app's view.

MPMoviePlayer dismiss when pressed

I have a MPMoviePlayer setup to play an intro movie to my application. That works just great, the only problem is that it lasts for 14 seconds, and I want to give my users a chance to skip the intro by pressing anywhere on the movie.
I have hidden the movie controls, as they are not needed.
Code:
NSString *introPath = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play];
Thank you!
EDIT: My initial solution won't work, because the movie is shown in a second window, layered on top of the app's main window (it's very rare to have more than one window in the view hierarchy on the iPhone). This solution, based on Apple's MoviePlayer sample code, does work:
. . .
// assuming you have prepared your movie player, as in the question
[self.intro play];
NSArray* windows = [[UIApplication sharedApplication] windows];
// There should be more than one window, because the movie plays in its own window
if ([windows count] > 1)
{
// The movie's window is the one that is active
UIWindow* moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
// Now we create an invisible control with the same size as the window
UIControl* overlay = [[[UIControl alloc] initWithFrame:moviePlayerWindow.frame]autorelease];
// We want to get notified whenever the overlay control is touched
[overlay addTarget:self action:#selector(movieWindowTouched:) forControlEvents:UIControlEventTouchDown];
// Add the overlay to the window's subviews
[moviePlayerWindow addSubview:overlay];
}
. . .
// This is the method we registered to be called when the movie window is touched
-(void)movieWindowTouched:(UIControl*)sender
{
[self.intro stop];
}
NB: You must save the reference to the movie player in an instance variable, and it's most convenient to declare a property that we can use to access it. That's why is use self.intro instead of just intro in the example. If you don't know how to declare an instance variable and a property, there is plenty of information on this site and elsewhere.
**** ORIGINAL ANSWER BELOW
(Doesn't work in this case, but in many similar scenarios, so I'll leave it as a warning and/or inspiring example.)
. . . if nothing else works I'd recommend subclassing UIWindow and making sure that your app delegate instantiates that instead of a normal UIWindow. You can intercept touches in that class and send a notification or cancel the movie directly (if you've stored a pointer to the MPMoviePlayer in an ivar on your window subclass).
#interface MyWindow : UIWindow {
}
#end
#implementation MyWindow
// All touch events get passed through this method
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// The screen has been touched, send a notification or stop the movie
return [super hitTest:point withEvent:event];
}
#end

Loading Multiple Movies in iPhone MPMoviePlayerController

-(void)initAndPlayMovie:(NSURL *)movieURL
{
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
self.moviePlayer = mp;
[mp release];
[self.moviePlayer play];
}
}
Here, in above code, We can pass just one movie URL. Isn't it possible to pass multiple urls to it?
So, Movie Player will load second url after playing first one.
Is it possible? How can we do that?
Right now, when I try to pass other url, after finishing first one.
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[self initAndPlayMovie:secondURL];
}
The Device First change its orientation while loading and after loading Device again come back to landscape mode.
How to resolve this problem?
You might want to change the orientation by changing the statusBar orientation before you start playing videos and change it back after you are done with all.
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:YES];
You should be able to call setContentURL just as the first movie is about to close to change to another movie. Check endPlaybackTime and fire off your method to invoke setContentURL one second prior to the movie ending.