Can not dismiss Modal View Controller with ios5 - ios5

I present one controller to play video:
[self presentModalViewController:movieController animated:YES];
and add an observer when finish palying:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedPlayback:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
-(void) movieFinishedPlayback:(NSNotification*)notification{
NSLog(#"........movieFinishedPlayback....... \n ");
[self dismissModalViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
This my VideoDetailViewController:
#import "VideoDetailViewController.h"
#import "PSStackedView.h"
#import "YunMaoIpadAppDelegate.h"
#define IpadAppDelegate ((YunMaoIpadAppDelegate *)[[UIApplication sharedApplication] delegate])
#define IphoneAppDelegate ((YunMaoIosAppDelegate *)[[UIApplication sharedApplication] delegate])
#interface VideoDetailViewController ()
#end
#implementation VideoDetailViewController
#synthesize video, moviePlayer, collectionsArray;
-(id)initWithVideo:(Video *)theVideo
{
self = [super initWithNibName:#"VideoDetailViewController" bundle:nil];
if (self) {
self.video = theVideo;
}
return self;
}
- (void)viewWillDisappear:(BOOL)animated
{
[moviePlayer pause];
//[self.navigationController setNavigationBarHidden:false animated:animated];
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated;
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[super viewDidDisappear:animated];
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor blackColor];
}
- (void) viewDidAppear:(BOOL)animated
{
//[moviePlayer play];
//[DejalBezelActivityView removeViewAnimated:YES];
[super viewDidAppear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:#selector(displayActivityView) withObject:self.moviePlayer.view afterDelay:0.1];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:video.link]];
[moviePlayer prepareToPlay];
//[moviePlayer setShouldAutoplay:NO];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
if([moviePlayer respondsToSelector:#selector(useApplicationAudioSession)])
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
NSLog(#"iPhone ios5.x");
[moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 480.0f, 320.0f)];
//moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
}
else{
NSLog(#"iPad ios5.x");
[moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f)];
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
[moviePlayer.view setFrame:[IpadAppDelegate window].bounds];
}
}
else
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
NSLog(#"iPhone ios6.x");
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
[moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
}
if(result.height == 568)
{
//moviePlayer.controlStyle = MPMovieControlStyleDefault;
[moviePlayer.view setFrame:self.view.bounds];
}
}
else{
NSLog(#"ipad ios 6.x");
[moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f)];
//[moviePlayer.view setFrame:[IpadAppDelegate window].bounds];
}
}
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
- (BOOL)shouldAutorotate{
return NO;
}
/*
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationLandscapeRight;
}
*/
- (IBAction)displayActivityView
{
[DejalBezelActivityView activityViewForView:self.moviePlayer.view withLabel:#"节目正在下载中,请稍后..."].showNetworkActivityIndicator = NO;
}
- (void)removeActivityView;
{
[DejalBezelActivityView removeViewAnimated:YES];
[[self class] cancelPreviousPerformRequestsWithTarget:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

This worked for me.
[self dismissViewControllerAnimated:NO completion:^{
[self.view removeFromSuperview];
}];
Hope it helps!

Before dismissing movieplayer do [moviePlayer stop]; and remove movieplayer.view from superview. Try dismissing after that. That might fix the issue.

Related

App crash on click of tab button second time [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
In my app i have tab bar and in it there is three tab button. but on one of it when i pressed it second time it crash the app. Other button are working fine.
This is the .m file code
-(void)viewWillAppear:(BOOL)animated
{
scrollView.contentSize = CGSizeMake(320, 500);
[super viewWillAppear:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Contact Us", #"Contact Us");
self.tabBarItem.image = [UIImage imageNamed:#"contactTab.png"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
scrollView.contentSize = CGSizeMake(320, 500);
scrollView.scrollEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
[textView becomeFirstResponder];
return YES;
}
- (void)keyboardWasShown:(NSNotification *)notification
{
// Step 1: Get the size of the keyboard.
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// Step 2: Adjust the bottom content inset of your scroll view by the keyboard height.
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
// Step 3: Scroll the target text field into view.
CGRect aRect = self.view.frame;
aRect.size.height -= keyboardSize.height;
if (!CGRectContainsPoint(aRect, self.activeTextField.frame.origin) )
{
CGPoint scrollPoint = CGPointMake(0.0, self.activeTextField.frame.origin.y - (keyboardSize.height-15));
[scrollView setContentOffset:scrollPoint animated:YES];
}
}
- (void) keyboardWillHide:(NSNotification *)notification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
// Set activeTextField to the current active textfield
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
self.activeTextField = textField;
}
// Set activeTextField to nil
- (void)textFieldDidEndEditing:(UITextField *)textField
{
self.activeTextField = nil;
}
// Dismiss the keyboard
- (IBAction)dismissKeyboard:(id)sender
{
[self.activeTextField resignFirstResponder];
}
So which code is crashing my app?
Edited :
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
tabBarController = [[UITabBarController alloc] init];
//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
HomeViewController * homeViewController = [[HomeViewController alloc] init];
UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeViewController];
ContactUsFormViewController *contactUsFormViewController = [[ContactUsFormViewController alloc] init];
UINavigationController *contactNav = [[UINavigationController alloc] initWithRootViewController:contactUsFormViewController];
BookingFormViewController *bookingFormViewController = [[BookingFormViewController alloc] init];
UINavigationController *bookingNav = [[UINavigationController alloc] initWithRootViewController:bookingFormViewController];
NSArray* controllers = [NSArray arrayWithObjects:homeNav,contactNav,bookingNav, nil];
tabBarController.viewControllers = controllers;
[self.window setRootViewController:tabBarController];
sleep(2);
[self.window makeKeyAndVisible];
return YES;
}
Thanks.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
scrollView.contentSize = CGSizeMake(320, 500);
scrollView.scrollEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
scrollView.contentSize = CGSizeMake(320, 500);
[super viewWillAppear:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Contact Us", #"Contact Us");
self.tabBarItem.image = [UIImage imageNamed:#"contactTab.png"];
}
return self;
}

AVAudioPlayer is playing again without being called play.

I have 2 views and video player and an audio player. when button on the first view is pressed. then audio and a video player start playing. And after the movie has stopped playing. next view is appear. when i press back button on the second view same audio is playing. Dont know where to start
- (id) init {
if (self = [super init]) {
movieName = #"03";
self.view = [[[OtsugeView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
}
return self;
}
- (void) toNext {
NSLog(#"OtsugeViewController:toNext");
[self.navigationController popViewControllerAnimated:NO];
}
- (void) toToppage
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.navigationController popToRootViewControllerAnimated:NO];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"Screen touch Otsuge View");
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Retry", #"Main Menu", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.cancelButtonIndex = 0;
[actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[actionSheet release];
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0: // Retry
[self presentModalViewController:mMoviePlayer animated:YES];
[self play];
break;
case 1: // Main Menu
[self toToppage];
break;
case 2: // Cancel
break;
default:
break;
}
}
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
mMoviePlayer.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
[self playSound:#"taiko_1"];
[(OtsugeView *)self.view renewImageView];
}
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
- (void) dealloc {
[super dealloc];
}
#end
and the movieplayerclass is
- (NSURL *)createURL
{
NSURL *mvURL;
NSBundle *bundle = [NSBundle mainBundle];
if (movieName != nil) {
if (bundle) {
NSString *mvPath = [bundle pathForResource:movieName ofType:#"m4v"];
if (mvPath) {
mvURL = [NSURL fileURLWithPath:mvPath];
}
}
}
return mvURL;
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
[aAudioPlayer setDelegate:nil];
[aAudioPlayer release];
NSLog(#"MovieViewController:audioHasFinished");
NSLog(#"%#", aAudioPlayer.url);
}
- (void)playSound:(NSString *)file {
NSURL *avURL;
NSString *avPath = [[NSBundle mainBundle] pathForResource:file ofType:#"m4a"];
if (avPath) {
avURL = [NSURL fileURLWithPath:avPath];
aAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:avURL error:nil];
[aAudioPlayer setDelegate:self];
[aAudioPlayer play];
NSLog(#"MovieViewController:playSound");
}
}
- (void)toNext {
// implementation sub classes
NSLog(#"MovieViewController:toNext");
}
- (void) clearVideo{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMoviePlayer.moviePlayer];
[mMoviePlayer release];
mMoviePlayer = nil;
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
NSLog(#"MovieViewController:moviePlaybackDidFinish");
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMoviePlayer.moviePlayer];
[self dismissModalViewControllerAnimated:YES];
[mMoviePlayer release];
mMoviePlayer = nil;
mPlayerPushed = NO;
[self toNext];
}
- (void) moviePreloadDidFinish : (NSNotification *)notification{
[self prepareFinished];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:mMoviePlayer.moviePlayer];
}
- (void) prepareFinished{
}
- (void) initPlayer{
if (mMoviePlayer != nil) {
[mMoviePlayer release];
}
mMoviePlayer = [[MoviePlayerViewController alloc] initWithContentURL:[self createURL]];
// Added 3.2 versions
[[NSNotificationCenter defaultCenter] removeObserver:mMoviePlayer
name:MPMoviePlayerPlaybackDidFinishNotification object:mMoviePlayer.moviePlayer];
[mMoviePlayer.moviePlayer setShouldAutoplay:NO];
mMoviePlayer.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
mMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
mMoviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMoviePlayer.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:mMoviePlayer.moviePlayer];
mPlayerPushed = YES;
}
- (void) play {
NSLog(#"MovieViewController:play");
[mMoviePlayer.moviePlayer prepareToPlay];
[mMoviePlayer.moviePlayer play];
}
- (void)viewWillAppear:(BOOL) animated {
if (!mMoviePlayer) {
[self initPlayer];
}
[super viewWillAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
NSLog(#"memory error!");
// Releases the view if it doesn't have a superview.
//[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
}
- (void)dealloc {
[nextController release];
[movieName release];
[super dealloc];
}
#end
The problem is in your second block of code:
The - (void) viewWillAppear:(BOOL)animated method has the following line in it:
[self playSound:#"taiko_1"];
This makes it play the sound, every time that the view is shown, including being shown a second time after dismissing a different view controller.
If you only want it to play once, then you need to move it somewhere else like viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
[self playSound:#"taiko_1"];
}

MPMoviePlayerController with UIPopoverController

I am using the MPMoviePlayerController to play a video on UIPopoverController.
When UIPopoverController dismiss video keeps on playing in background. Is there any way to stop and release MPMoviePlayer.
In my code There is FirstViewController and ViewVideoController which has function:
#implementation FirstViewController
- (void)popOverViewDisplay:(id)sender {
//if(![popoverController isPopoverVisible]){
NSLog(#"my popover....");
ViewVideoController *videoController = [[[ViewVideoController alloc] initWithNibName:nil bundle:nil] autorelease];
videoController.contentSizeForViewInPopover =CGSizeMake(550, 460);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:videoController];
popoverController.delegate = self;
[videoController release];
popViewBtnFrame = CGRectMake(299, 357, 63, 42);
[popoverController presentPopoverFromRect:popViewBtnFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
//[self.popoverController release];
NSLog(#" if loop popover dismissed");
ViewVideoController *videoController = [[ViewVideoController alloc] initWithNibName:#"ViewVideoController" bundle:nil];
[videoController unloading];
}
NSLog(#"popover dismissed");
}
on button press player start playing in popoverController.
#implementation ViewVideoController
- (void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:#"AlphabetTrain" ofType:#"mov"];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
//player.movieControlMode = MPMovieControlModeHidden;
player.controlStyle = MPMovieControlStyleDefault;
player.view.frame = CGRectMake(75.0f, 80.0f, 400.0f, 300.0f);
[[self view] setCenter:CGPointMake( [[self view] bounds].size.width / 2, [[self view] bounds].size.height / 2)];
[self.view addSubview:player.view];
[player play];
//[player release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[super viewDidLoad];
}
- (void)myMovieFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerController* player1 = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player1];
NSLog(#"stop player");
[player stop];
}
- (void)unloading { //this function called in firstviewcontroller to stop player on dismiss
NSLog(#"unloading player");
//[player endSeeking];
[self.player stop];
}
When I dismiss ViewVideoController player keeps on playing. Is there any way to stop/release player on dismiss of ViewVideoController
You can use delegate method
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[moviePlayer stop];
}

MPMoviePlayer Bad-Access error after playing video

I´ve created an new ViewController (only with the .h and .m file) and added that code to play a video. After the video has finished, i get a "Exe_bad_access" error.
Error message when adding "NSZombieEnabled=true" to the excecutable as a argument:
"TestPlayingVideo[654:207]
-[MPMoviePlayerController stop]: message sent to deallocated instance
0x63042d0"
Whats wrong with that? How can i do correct memory management when playing video?
#import "TestPlayingVideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#implementation TestPlayingVideoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor darkGrayColor]];
UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(50 , 50, 200, 25)];
[btn setTitle:#"press me" forState:UIControlStateNormal];
[btn addTarget:self action:#selector(action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn release];
}
- (void)action:(id)sender
{
NSLog(#"UIButton was clicked");
NSString *url = [[NSBundle mainBundle] pathForResource:#"mymovie" ofType:#"m4v"];
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];
[moviePlayerController.moviePlayer play];
//[self.view addSubview:moviePlayerController.view];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
}
- (void) moviePlayBackComplete:(NSNotification*) notification {
MPMoviePlayerController* player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[self dismissMoviePlayerViewControllerAnimated];
[player stop];
//[self.view removeFromSuperView];
[player release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
There's a lot of confusion here over what you're releasing: for example, here's your main alloc of your movie player:
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
But what you are releasing isn't this moviePlayerController - you're only releasing the .moviePlayer property of your MPMoviePlayerController. Notice when you create your NSNotification you're passing moviePlayerController.moviePlayer, not simply moviePlayerController.
So you're not releasing your moviePlayerController, you're in fact attempting to release a property of that object. Which you shouldn't do - you should release the object, and let it worry about releasing its properties.

How to build a bar on the keyboard

I want to dismiss keyboard by click dismiss button ,How to build a bar on the keyboard? like this:
(source: alexcurylo.com)
It was answered here. Basically, you send a resignFirstResponder message to the UITextView. Of course, you will put that code on your button's delegate.
Try to put following code. It might work for you.
Put following variables in your viewController.h file
UIToolbar *keyboardToolbar;
id notisender;
BOOL isAlreadyResigned;
float kx,ky,kh,kw;
Now put following code in you viewController.m file.
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated{
isAlreadyResigned=YES;
[self keyboardToolbarShouldShow];
[self keyboardToolbarShouldShow];
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated{
[self keyboardToolbarShouldNotShow];
[super viewWillDisappear:animated];
}
#pragma mark keyboardWillShow methods
-(void)keyboardToolbarShouldShow {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardhide:)
name:UIKeyboardWillHideNotification
object:nil];
}
-(void)keyboardToolbarShouldNotShow {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
if(!isAlreadyResigned){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillNotShow:)
name:UIKeyboardWillShowNotification
object:nil];
[GEEtxtMsg becomeFirstResponder];
}
}
-(void)keyboardWillShow : (NSNotification *)sender {
#try {
// NSLog(#"notification in first view");
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *keyboard in [keyboardWindow subviews]) {
NSLog(#"keyboard description - %#",[keyboard description]);
if([[keyboard description] hasPrefix:#"<UIKeyboard"] == YES) {
NSValue *v = [[sender userInfo] valueForKey:UIKeyboardBoundsUserInfoKey];
CGRect kbBounds = [v CGRectValue];
if(keyboardToolbar == nil) {
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
keyboardToolbar.barStyle=UIBarStyleBlackOpaque;
keyboardToolbar.tintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(dismissKeyboard)];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *items = [[NSArray alloc] initWithObjects:flex, barButtonItem, nil];
[keyboardToolbar setItems:items];
[items release];
}
[keyboardToolbar removeFromSuperview];
keyboardToolbar.frame = CGRectMake(0, 0, kbBounds.size.width, 45);
[keyboard addSubview:keyboardToolbar];
NSLog(#"x=%f y=%f width=%f height=%f",kbBounds.origin.x, kbBounds.origin.y, kbBounds.size.width, kbBounds.size.height);
kx=kbBounds.origin.x; ky=kbBounds.origin.y;
kh=kbBounds.size.height; kw=kbBounds.size.width;
keyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y, kbBounds.size.width, kbBounds.size.height + 87);
isAlreadyResigned=NO;
for(UIView* subKeyboard in [keyboard subviews]) {
if([[subKeyboard description] hasPrefix:#"<UIKeyboardImpl"] == YES) {
subKeyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y - 45, kbBounds.size.width, kbBounds.size.height);
}
}
}
}
}
} #catch (NSException * e) {
NSLog(#"Problem in keyboardWillShow:%#",e);
}
}
-(void)keyboardWillNotShow : (NSNotification *)sender {
#try {
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *keyboard in [keyboardWindow subviews]) {
if([[keyboard description] hasPrefix:#"<UIKeyboard"] == YES) {
// NSValue *v = [[sender userInfo] valueForKey:UIKeyboardBoundsUserInfoKey];
// CGRect kbBounds = [v CGRectValue];
if([[keyboard subviews] containsObject:keyboardToolbar]){
[keyboardToolbar removeFromSuperview];
}
if(!isAlreadyResigned){
isAlreadyResigned=YES;
keyboard.bounds = CGRectMake(kx,ky,kw,kh);
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
for(UIView* subKeyboard in [keyboard subviews]) {
if([[subKeyboard description] hasPrefix:#"<UIKeyboardImpl"] == YES) {
subKeyboard.bounds = CGRectMake(0, 0,0, 0);
}
}
}
}
}
}
} #catch (NSException * e) {
NSLog(#"Problem in keyboardWillShow:%#",e);
}
}
-(void)dismissKeyboard {
[self resignTextFields];
}
-(void)keyboardhide:(NSNotification *)noti {
notisender = noti;
}
Here you can build a bar on a keyboard
Take static toolbar on xib and take one button and put it on toolbar, and make toolbar hidden ,now
write code in your method when you create a toolbar ,like if you want to create toolbar on textview begin editing method then,
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.26];
[tlBar setFrame:CGRectMake(0, 220, 320, 44)];
tlBar.hidden=NO;
[UIView commitAnimations];
}
And when you dismiss keyboard write this method and call this method when toolbar button pressed
-(IBAction)kbAway:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[tlBar setFrame:CGRectMake(0, 480, 320, 44)];
[UIView commitAnimations];
[txtviewmessage resignFirstResponder];
[txtsubject resignFirstResponder];
[txttemplatename resignFirstResponder];
}
Hope this will help you..