Issue..with video playback on iPad with MPMoviePlayerViewController - iphone

I have been fighting some code for about a week, and am hoping that someone else may have experienced this problem and can point me in the right direction.
I am using the MPMoviePlayerViewController to play a video on the iPad. The primary problem is that it works FLAWLESSLY on the iPad Simulator, but will not play at all on the iPad. I have tried re-encoding the video to make sure that isn't an issue. The video I'm using is currently a 480x360 video encoded with H.264 Basline 3.0 with AAC/LC audio. The video plays fine on the iPhone, and also does play through Safari on the iPad. The video actually loads, and you can scrub through the video with the scrubber bar and see that it is there. The frames actually display, but just will not play. If you click play, it just immediately stops. Even when I have mp.moviePlayer.shouldAutoplay=YES set, you can see the player attempt to play, but only for a split second (maybe 1 frame?).
I have tried just adding view with the following code:
in .h
------
MPMoviePlayerViewController *vidViewController;
#property (readwrite, retain) MPMoviePlayerViewController *vidViewController;
in .m
------
MPMoviePlayerViewController *mp=[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
[mp shouldAutorotateToInterfaceOrientation:YES];
mp.moviePlayer.scalingMode=MPMovieScalingModeAspectFit;
mp.moviePlayer.shouldAutoplay=YES;
mp.moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
[videoURL release];
self.vidViewController = mp;
[mp release];
[self.view addSubview:vidViewController.view];
float w = self.view.frame.size.width;
float h = w * 0.75;
self.vidViewController.view.frame = CGRectMake(0, 0, w, h);
I have also just tried to do a:
[self presentMoviePlayerViewControllerAnimated:self.vidViewController];
which I actually can not get to orient properly...always shows up in Portrait and almost completely off the screen on the bottom, and the app is only intended to run in either of the Landscape views...
If anybody needs more info, just let me know. I'm about at my wits end on this. ANY help will be GREATLY appreciated.

I see 2 problems here.
First you are not setting the frame of the view. Try adding
mp.view.frame = self.view.frame;
This is what fixed it for me.
Next the shouldAutorotateToInterfaceOrientation does not need to be called. This method simply tells you if the view supports an orientation. Check the Apple docs.

You may want to try shutting down the iPad (powering off), remove and re-install the app.

Just add a line after you add the movie player to the view:
[self.vidViewController.moviePlayer play];
See if it helps.
Thanks,
Madhup

Related

MPMoviePlayerController dismisses my UIImagePickerController

I have an iPhone app where I load an UIImagePickerController onto a UIViewController. I then have a custom view on top of the camera. Now when the user takes a photo it is loaded onto a UIImageView which presents it to the user asking if you want to use that photo or take another (removing the image from the UIImageView). This works perfectly.
Now If the user has just recorded a video I wanted to take a snapshot preview somewhere in the video and present it as a static image in the same UIImageView. I do this with the following code:
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] init];
videoPlayer.shouldAutoplay = NO;
[videoPlayer setContentURL:[info valueForKey:UIImagePickerControllerMediaURL]];
UIImage *videoScreenShot = [videoPlayer thumbnailImageAtTime:(videoPlayer.duration/2.0) timeOption:MPMovieTimeOptionNearestKeyFrame];
photoPreview.image = videoScreenShot;
[videoPlayer release]
This works as intended. The problem is if I want to take another video. When I call:
[videoPlayer setContentURL:[info valueForKey:UIImagePickerControllerMediaURL]];
The camera shutter closes and the camera is seemingly dismissed. Trying to take a picture or recording video gives me:
UIImagePickerController: ignoring request to take picture; camera is not yet ready.
UIImagePickerController: ignoring request to start video capture; camera is not yet ready.
I've tried calling the following after, which has no effect:
myImagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
[myImagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
I tried adding the UIImagePickerController to the UIIViewController again, which caused some fantastic freeze-ups.
Finally I tried commenting out the UIViewController's [super didReceivedMemoryWarning] line of didReceivedMemoryWarning. Which also had no effect.
I'm guessing MPMoviePlayerController takes over something UIImagePicker also needs. How do I give it back?
I would suggest setting your MPMoviePlayerController to nil before showing the UIImagePickerController, or maybe taking its view out of the interface temporarily. Both of these contain a movie player view, but there can be only one movie player view at a time in your application's interface. Thus they can interfere with each other, and that might be what's happening to you.

MPMoviePlayer standard interface play/pause status reflection issue

One of my components makes heavy use of MPMoviePlayerController and recently showed a weird bug; when using the standard user interface (e.g. MPMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;) the player never changes the state of the play/pause button (that thingy in the middle of my screenshot).
The functionality stays intact but the player state is not reflected by the UI.
When bringing up the controls by tapping on the screen while a movie is playing, I see a play-symbol. What I expect would be a pause-symbol as the player is currently playing. When tapping onto the play-symbol, the player goes into pause-mode. The symbol however does not change. When tapping again onto that play symbol, the player continues the playback, just as expected.
The problem has been introduced with iOS5 and did not occur on previous iOS versions.
For validating an iOS5 issues, I created a minimalistic player that is not using my own framework and sure enough the problem did not occur, hence it must be my code triggering this quirk. Unfortunately, my code is pretty damn large (about 3k lines) so I can not post it here.
I know chances of someone being able to answer this question without source code are pretty slim as it seems to be directly connected to my code. Being desperate as I am by now, I just took the chances and hope for a little wonder, somebody actually had such issue and knows how to trigger / remove it.
Well, it seems I found the answer (and what I would call an iOS5 bug)...
The reason for MPMoviePlayerController getting irritate on the status of the play button simply was the order of my initializing code.
For triggering this issue, all you have to do is run this code;
moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.shouldAutoplay = YES;
moviePlayer.fullscreen = NO;
moviePlayer.view.frame = self.view.bounds;
moviePlayer.currentPlaybackTime = 0.0;
moviePlayer.initialPlaybackTime = 0.0;
[moviePlayer setContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
[self.view addSubview:moviePlayer.view];
You will see a player UI which does not change its Pay/Pause state.
For getting things to work properly again, you have to move the setContentURL call before setting the playback-time.
moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.shouldAutoplay = YES;
moviePlayer.fullscreen = NO;
moviePlayer.view.frame = self.view.bounds;
[moviePlayer setContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
moviePlayer.currentPlaybackTime = 0.0;
moviePlayer.initialPlaybackTime = 0.0;
[self.view addSubview:moviePlayer.view];
I did submit a bug at Apple (Radar Bug ID# 10484668) - will keep you posted on their answer.
OpenRadar Bug Report
I also was frequently seeing this behavior, but unfortunately simply switching the order of calls to setContentURL and setting initial and playback times made no difference.
I discovered what I was doing wrong though. I was setting the playback times to -1 to indicate start of the stream when I should have been specifying zero. Changing this fixed the problem for me.

Playing videos on iPad with a specific style

i have some mp4 files which are to be played in my iPad app.. I am able to do that quite well. right now i have a play button on blank black space in my app and the video plays after i tap the play button. The user will only come to know the content of the video after playing it.. But, i want the user to know about the video before playing itself . instead of the default black screen i want to show the video starting screen to make the video more interesting. To put it in simple words, i want my video space to be similar to youtube... IS there any way i which this can be done?? Thanks
Subclass MPMoviePlayerController (or however you're playing your video.. if you already use a custom class just add the code in there) and in viewDidAppear initialise a UIImageView with frame size equal to self.view.bounds using whatever background image you want for the loading screen. Add the UIImageView as a subview of self.view and call sendSubviewToBack: on it. When the player is ready to play, it will start drawing video frames on top of your subview, and you should not see it again.
- (void)viewDidAppear
{
UIImageView *loadingImage = [[UIImageView alloc] initWithImage:myImage];
[loadingImage setFrame:self.view.bounds];
[self.view addSubview:loadingImage];
[self.view sendSubviewToBack:loadingImage];
[super viewDidAppear];
}

Play a video inside a view using MPMoviePlayerController?

I am trying to play video inside a view so I can move it around, perform layout together with other views, but I can't seem to get it work to using MPMoviePlayerController. I came across this link on how to play video in portrait mode but this is not possible because the video source is coming from the web and should be playable in different platforms not only on iPhone.
I've been successful rotating the video and scaling it but it is still contained in a UIWindow which fills the whole screen. Is there a way to create an intermediate UIWindow but not visible in the current screen, so you can play the video there and probably add subviews and return everything as a UIView where I can place it anywhere? Similar to creating a CGGraphics context draw objects there and output as an image. This would also prevent the current screen from rotating from portrait to landscape.
----- 2010/06/22 06:10+08:00 ---
IN response to Jasarien's answer (below), actually it is possible to rotate and scale a video. After the video has preloaded it creates another instance of UIWindow which then becomes the keywindow at that moment. By creating a callback selector at MPMoviePlayerContentPreloadDidFinishNotification, it is possible to apply transform modification of the current keywindow.
-(void)myMovieFinishedPreloading:(NSNotification*)aNotification {
NSArray *windows = [[UIApplication sharedApplication] windows];
UIWindow *moviePlayerWindow = nil;
if ([windows count] > 1)
{
moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
}
CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
[moviePlayerWindow setTransform:transform];
}
Now my question is now that its part of UIWindow and since UIWindow is a UIView subclass, is it possible to subview this UIView? Also I can't seem to disable the autorotate behavior upon preloading of the video.
Video on the iPhone is played fullscreen at all times. The iPad with iOS 3.2 has APIs that allow a video to be treated as a normal view.
For the iPhone, without writing your own video view you're not going to be able to get the functionality you want.
Check out AVPlayer and AVPlayerLayer.

iPad rotation bug when using MPMoviePlayerViewController

Issue summary
Changing the orientation of an iPad device or simulator while playing a video using MPMoviePlayerViewController results in an inconsistent rotation state upon dismissal of the video player. This is a known bug in iPad SDK 3.2, documented at http://www.openradar.me/8012810
Sample project
I have prepared a minimal sample project using the View-based Application template from Xcode 3.2.2, using the following code to launch the player
NSURL *movieUrl = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];
The code is available on GitHub at http://github.com/adamalex/FullScreenMovie or direct download using http://github.com/adamalex/FullScreenMovie/zipball/master
Steps to reproduce
Obtain the project using the information above
Launch the project with the iPad simulator or device
Tap the button to begin playing the video
Rotate the iPad by 90 degrees
Dismiss the video
Note the UIStatusBar is out of sync with the application UI
Objective
I have contacted Apple and they have confirmed this is a bug that is being investigated. I would like to discuss temporary workarounds that use public APIs safe for submission to the App Store. I am going to open a developer support case with Apple as well and will report back with my own progress.
Successful response from Apple Developer Technical Support!
This is a known bug and a we're received a number of duplicate bug reports and so iOS engineering is aware of the issue and we do have a temporary workaround as suggested by iOS engineering.
You will need to implement this in the view controller which presents the movie player.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self performSelector:#selector(fixStatusBar) withObject:nil afterDelay:0];
}
- (void)fixStatusBar {
[[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
}
While this is somewhat ugly, it should fix the issue for now. It would be recommended to remove this code once the bug is fixed in the system.
This took care of the issue completely for me, and you can revisit http://github.com/adamalex/FullScreenMovie for the code with the fix applied.
This also solves an iPhone/iPodTouch rotation issue that I was struggling with. I am developing a universal app in which each view displays a different image depending on whether the device is in portrait or landscape orientation. Buttons are used to navigate between views.
If the app is running on the device and a portrait view is rotated to landscape, my image switching takes place. If the device is then placed flat on a table top and the button is tapped to display the next view, the view appears in landscape but shows the portrait image instead. I solved the problem by forcing a portrait view to appear by detecting for face up and down, but Apple's code solved this problem (as well as the similar movie problem I was also experiencing).
Many thanks for reporting the bug - I assumed it was just my bad coding...