iPhone 4.0:MPMoviePlayerController doesn't play the video properly - iphone

I am using MPMoviePlayerController class for playing the video in built-in media player on iPhone. The project works fine on iPhone 3.0 simulator or device, but it doesn't show the video view on iPhone 4.0 simulator or device, rather than i could able to hear the sound, no built-in player video display.
Does anyone come across this issue and how to resolve it?
UPDATED:
I placed my code below: Now the problem is, i call the code playing the video when clicking on a row in the TableView. When i click on a row, it started playing the video but the TableView is not being completely hidden. So i could see Tableview and Video, both screens have overwritten. How do i push back the TableView completely when video is playing and come back to the TableView after video view is done?
NSURL *url = [NSURL URLWithString:strUrl];
mP = [ [MPMoviePlayerController alloc] initWithContentURL:url ];
[mP setControlStyle:MPMovieControlStyleFullscreen];
[mP setFullscreen:YES];
[mP play];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
// Rotate the view for landscape playback
[[self view] setBounds:CGRectMake(0, 0, 480, 320)];
[[self view] setCenter:CGPointMake(160, 240)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[[mP view] setFrame:CGRectMake(0, 0, 480, 320)];
// Add movie player as subview
[[self view] addSubview:[mP view]];

You have to remember that in iOS4 MPMoviePlayerController is not playing in fullscreen by default. You have to add your moviePlayer.view on the superview.
If you want to play the video on fullscreen you should look at the MPMoviePlayerViewController reference

Related

iphone play video in a view not fullscreen

I was looking for answer in other questions but found out it's impossible to play video in iPhone in a view and not fullscreen, but maybe it has changed with the new versions? Somebody knows anything?
Use MPMoviePlayerController for playing the video and set the frame where you want to display it in the layout.
// Create custom movie player
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:URL];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(onMSAASDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setFullscreen:FALSE];
//---play partial screen---
moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
[self.view addSubview:moviePlayer.view];

MPMoviePlayerController in background doesn't leave page when we change scene

I am using MPMoviePlayerController to play a video in the background of a CCMenu. So I have a video playing behind some buttons. When I switch views/scenes, I want the moviePlayer to leave the scene the same as the buttons/images on that layer/scene.
The code to play the movie in the background is as follows:
-(void)playMainMenuVideo{
NSString *path=[[NSBundle mainBundle] pathForResource:#"MYMMainMenu" ofType:#"mov"];
MPMoviePlayerViewController * player=[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
[[player view] setFrame:[[[CCDirector sharedDirector]view] bounds]];
player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[[[CCDirector sharedDirector]view] addSubview:[player view]];
[[[CCDirector sharedDirector]view] sendSubviewToBack:player.view];
UIView* glView = [CCDirector sharedDirector].view; // attention
[glView.superview insertSubview:player.view atIndex:0]; // attention
glView.opaque = NO; // attention
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // attention
}
This works perfect, In the app delegate I also changed
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGB565 // To kEAGLColorFormatRGBA8
Lastly I want to do a page turn like so:
[[CCDirector sharedDirector] replaceScene: [CCTransitionPageTurn transitionWithDuration:1.0 scene:[FirstPageViewController scene]]];
But only the sprites will leave the scene, the video stays playing in the background. How can I fix this? Thanks in advance
I figured it out.
1) Setup notification for when video is done playing.
2) When its done playing, place an image of the last frame of the video, over the video.
3) Then set these properties back to original
UIView* glView = [CCDirector sharedDirector].view; // attention
glView.opaque = YES; // attention
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
4)Remove MPMoviePlayerController
Happy Coding everyone :)

Camera orientation in landscape only in iphone

In my application I am using camera to take photos, and I want to use a image as overlay on the camera. the camera should show the landscape right only as my application is in landscape right mode. I am adding the UIImagePicker as subview over the view , and i am using the below code to change it to landscape right mode
CGAffineTransform transform=imgPicker.view.transform;
transform=CGAffineTransformRotate(transform, -90*M_PI/180);
transform=CGAffineTransformTranslate(transform, -52, -47);
[imgPicker setCameraViewTransform:transform];
And while I am adding any UIImageView as overlay for the camera, the imageview is not adding as landscape right. its adding in portrait.
This is my code:
picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
[picker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOff];
[self.view addSubview:picker.view];
picker.view.frame=CGRectMake(0, 0, 480, 320);
picker.cameraOverlayView.frame=picker.view.frame;
CGAffineTransform transform=picker.view.transform;
transform=CGAffineTransformRotate(transform, -90*M_PI/180);
transform=CGAffineTransformTranslate(transform, -52, -47);
[picker setCameraViewTransform:transform];
[picker setWantsFullScreenLayout:YES];
[picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 120, 120)];
theView.backgroundColor = [UIColor yellowColor];
[picker setCameraOverlayView:theView];
Please tell me where I am doing wrong
Thanks in advance

movie playback small not full size

I am developing a iphone app and I have a uiwebview which has a video on the page. When I press play the video plays in full screen. Is there a way I can make it so when I press play the video plays in a custom size and not full screen?
Use MPMoviePlayerController
From Apple:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];

iOS 4.3 Inline MPMoviePlayerController

I am using MPMoviePlayerController in my UIView and the goal is to put it there on View as inline view. The problem is that the code doesn't work except the full screen.
-(IBAction)startVideo {
//start video here
NSURL *path = [[NSURL alloc] initWithString:[self localVideoPath:NO]];
// Create custom movie player
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:path] autorelease];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setFullscreen:FALSE];
// May help to reduce latency
[moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(onMSAASDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
//---play partial screen---
//moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
moviePlayer.view.frame = image.frame;
//[[moviePlayer view] setFrame: [image bounds]];
[image removeFromSuperview];
[self.view addSubview:moviePlayer.view];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
// Prep and play the movie
[moviePlayer play];
}
The sample code from Apple is flawed or let's say outdated. You need to add the moviePlayer's view as subview to your view. Something like this:
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:path] autorelease];
...
// Adjust positioning where I used the bound of the outer view (of type UIView)
moviePlayer.view.frame = outerView.bounds;
// Now add the movie player to the outer view
[outerView addSubView:moviePlayer.view];
...
This should do the trick.
Sorry, I did not see that you added the subview already.
Okay, for a sample code you can take the XCode sample project called MoviePlayer_iPhone (inside the XCode documentation for MPMoviePlayerController you'll find a link for the MoviePlayer sample project) and just adjust AppDelegate's initAndPlayMovie this way:
-(void)initAndPlayMovie:(NSURL *)movieURL
{
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
// save the movie player object
self.moviePlayer = mp;
[mp release];
// Apply the user specified settings to the movie player object
[self setMoviePlayerUserSettings];
self.moviePlayer.view.frame = self.window.bounds;
[self.window addSubview:self.moviePlayer.view];
// Play the movie!
[self.moviePlayer play];
}
}
This one is crude because it does not set the frame or centers the view but it should display the movie when you go to local and click on Play Movie.
The only drawback I saw was that the fullscreen is not going black. That said the sample project is pretty weird and not very well written. That said it displays the non-fullscreen video.