The following is the code I used to play a movie:
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
float screenWidth = self.view.frame.size.width;
float screenHeight = self.view.frame.size.height;
[playerViewController.view setFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[self.view addSubview:playerViewController.view];
[self.view setUserInteractionEnabled:YES];
//---play movie---
player = [playerViewController moviePlayer];
[player setControlStyle:MPMovieControlStyleNone];
[player setFullscreen:TRUE];
[player play];
skipButton = [UIButton buttonWithType:UIButtonTypeCustom];
[skipButton setTitle:#"Skip" forState:UIControlStateNormal];
skipButton.frame = CGRectMake(0, 0, 150, 50);
[skipButton setCenter:CGPointMake(screenWidth - 30 - skipButton.frame.size.width, 100)];
[skipButton addTarget:self action:#selector(skipMovie) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:skipButton];
But, I have some issue with these on iPad1. If I did not use the setFullScreen method, the movie didn't play in FullScreen mode, even if I set the Rect (1024x768). But if I set these, the movie does play in FullScreen, but my #skipButton is not visible.
If i use:
[self.view addSubview:playerViewController.view];
after
[player play];
the first issue happened. The code works properly in iPad2, even without setFullScreen.
Does anyone have any ideas?
[playerViewController.view bringSubviewToFront: skipButton]
doesn't make any change!!!!
I think you can solve this issue by using this method
[playerViewController.view bringSubviewToFront: skipButton];
Please call this function only after your movie player loads the movie.
I wonder if anyone could kindly assist, I am trying to adjust my app so that it recognises the full screen of the iPhone 5, it all works fine on other screens now, however my initial screen I am having an issue with, as I fade the top and bottom bars out of view, the top works fine however the bottom does not, could anyone assist with the code to help me get it to work on the iPhone 5? As right now, the bar is too high on the screen on iPhone 5 and does not fade out of view...
- (void)barwillGo
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 320, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 430, 320, 50)];
}
else {
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 481, 320, 50)];
}
}
completion:nil];
}
else {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 768, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 768, 50)];
[bottomBar setFrame:CGRectMake(0, 974, 768, 50)];
}
else {
[topBar setFrame:CGRectMake(0, -51, 768, 50)];
[bottomBar setFrame:CGRectMake(0, 1025, 768, 50)];
}
}
completion:nil];
}
}
You hard coded the CGRect values of the bottomBar to the 3.5 inch screen dimensions.
Try something like this within your first animation block:
CGRect bounds = topView.superview.bounds;
CGFloat topRectY, bottomRectY;
if(topBar.frame.origin.y == -50){
topRectY = 0;
bottomRectY = bounds.size.height - 50;
} else {
topRectY = -50;
bottomRectY = bounds.size.height;
}
topBar.frame = CGRectMake(0, topRectY, bounds.size.width, 50);
bottomBar.frame = CGRectMake(0, bottomRectY, bounds.size.width, 50);
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 320, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 430, 320, 50)];
}
else {
//check device iphone5 or not
if (screenHeight != 568.0f) {
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 481, 320, 50)];
}
else
{
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 569, 320, 50)];
}
}
}
completion:nil];
}
I am currently working on an app in which I need to play a video. Everything is working fine. But if my application is sent to the background and then again to the foreground it shows a solid black screen.
Please provide me with a solution to this problem.
[player.view setFrame:CGRectMake(0, 0, 480, 278)];
[player.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
outputURL = [NSURL fileURLWithPath:filePath];
[player setContentURL:outputURL];
[player setShouldAutoplay:NO];
player.repeatMode = MPMovieRepeatModeNone;
player.controlStyle = MPMovieControlStyleNone ;
player.scalingMode = MPMovieScalingModeAspectFit;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player prepareToPlay];
[player pause];
[self.view addSubview: player.view];
Just see this solution
For MPMoviePlayer
I am using MPMoviePlayerController for playing the media . I want to set the image at the background of the player.The image is set accordingly but when i set the bounds for the image then the image is not set according to bounds . I have tried following code:
UIImageView *imageView=[[UIImageView alloc]initWithImage:[operationControl getCoverImage:stringId]];
imageView.bounds=CGRectMake(0, 100, 200, 200);
[moviePlayer.backgroundView addSubview:imageView];
[moviePlayer.backgroundView setBackgroundColor:[UIColor purpleColor]];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
I have tested everything but I cant get it to work.
This is how I set up my program:
CGRect contentRect = CGRectMake(0, 0, 480, 320);
CGRect screenBounds = [[UIScreen mainScreen] bounds];
_window = [[UIWindow alloc] initWithFrame: contentRect];
_view = [[GLView alloc] initWithFrame: screenBounds];
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
_view.transform = transform;
_window.frame = contentRect;
_window.bounds = contentRect;
_window.window.bounds = contentRect;
_window.frame = contentRect;
_view.window.bounds = contentRect;
_view.bounds = contentRect;
_view.bounds = contentRect;
_view.frame = contentRect;
[_window addSubview: _view];
[_window makeKeyAndVisible];
I set up my opengl like this:
glViewport(0, 0, 480, 320);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof( 0, 480, 0, 320, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
and as you can see one third from the right is black? what am i missing?
You should set rotation in your model/view matrix and not in the view.