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.
Related
i need help in making status bar translucent. In some parts of app its working fine, and in other its not.
This is how status bar is coming if i show navugation bar.
this is how is showing when i remove the navigation bar.
I need to show the navigation bar but status bar should be translucent. The background image is pushed down with the navigation bar.I have set the background image programmatically making a base class.
-(void)addBackGroundImage{
self.backGroundImage=[[UIImageView alloc] init];
self.backGroundImage.translatesAutoresizingMaskIntoConstraints=NO;
[self.backGroundImage setImage:[UIImage imageNamed:#"background"]];
self.backGroundImage.contentMode=UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backGroundImage];
[self.view sendSubviewToBack:self.backGroundImage];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|[_backGroundImage]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_backGroundImage)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-(0)-[_backGroundImage]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_backGroundImage)]];
AppDelegate *objAppDelegate=[[UIApplication sharedApplication] delegate];
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 20)];
view.backgroundColor=[UIColor clearColor];
[view setAlpha:0.2];
}
-(void)updateBackgroundImage:(UIImage *)bgImage{
[self.backGroundImage setImage:bgImage];
}
It is actually what you need to completely remove default header background (statusBar + navigationBar) and set your own:
// ViewController.m
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.tintColor = [UIColor yourColor]; // Set your tint color
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.opaque = NO;
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Your_Background_Image"]];
[self.view addSubview:bgView];
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];
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];
OK, i am making a Coloring app and it has a "Save" button that will take the screen shot of the view where the drawing is.
I have 6 images to color. In the intro page there 6 buttons, each will link you to a particular coloring page.
All are working well including the "Save" button except for one. All coloring views has the same contents and functions but in one image, it crashes the iPad whenever i clicked the "Save" button.
Here's some of my codes:
On Button Click:
[self saveScreenshotToPhotosAlbum];
camFlash = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[camFlash setBackgroundColor:[UIColor whiteColor]];
[camFlash setAlpha:0.0];
[cbHolder addSubview:camFlash];
[cbHolder bringSubviewToFront:camFlash];
[UIView beginAnimations:#"Flash-On" context:NULL];
[UIView setAnimationDuration:0.2];
[UIView setAnimationRepeatAutoreverses:NO];
[camFlash setAlpha:1.0];
[UIView commitAnimations];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"flash" ofType:#"wav"];
AVAudioPlayer *flashSFX = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL];
flashSFX.volume = 0.5;
flashSFX.numberOfLoops = 0;
self->camFlashSFX = flashSFX;
if ([flashSFX currentTime] != 0) [flashSFX setCurrentTime:0];
[flashSFX play];
[self performSelector:#selector(removeFlash) withObject:nil afterDelay:0.2];
Remove Flash:
- (void) removeFlash
{
[camFlash removeFromSuperview];
}
For the screenshot:
- (UIImage*)captureView {
UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
CGContextRef context = UIGraphicsGetCurrentContext();
[cbHolder.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)saveScreenshotToPhotosAlbum {
UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil);
}
This one is for the button that will show the coloring page:
uc4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tpUncolored1.png"]];
[uc4 setUserInteractionEnabled:YES];
[uc4 setFrame:CGRectMake(0, 0, 1024, 768)];
[cbHolder addSubview:uc4];
clrd4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tpColored1.png"]];
[clrd4 setUserInteractionEnabled:YES];
[clrd4 setFrame:CGRectMake(0, 0, 1024, 768)];
[cbHolder addSubview:clrd4];
[UIView beginAnimations:#"fabe-out" context:NULL];
[UIView setAnimationDuration:1.5];
[clrd4 setAlpha:0.0];
[UIView commitAnimations];
[self performSelector:#selector(cb4) withObject:nil afterDelay:1.5];
AND I AM HAVING THIS ERROR:
Thread 5: EXC_BAD_ACCESS (code=1, address=0xd9bbd40)
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