I'm using MPMoviePlayerViewController to play video. In my app I am playing video(s) that are in the app, using the standard MPMoviePlayerController class. It works fine on iOS 7 and 8
The first time around around this works great, however after watching 1 video if you try and watch something else the app crashes on MPMoviePlayerController's play method with the error:
: CGContextSaveGState: invalid context 0x0
: CGContextClipToRect: invalid context 0x0
: CGContextTranslateCTM: invalid context 0x0
: CGContextDrawShading: invalid context 0x0
: CGContextRestoreGState: invalid context 0x0
*** -[MPMoviePlayerController retain]: message sent to deallocated instance 0x1e5718b0
I can not figure out why this is happening.
Here is my code:
AFPlayerViewController.h
#property (strong, nonatomic) MPMoviePlayerViewController *playerViewController;
- (id)initWithContentURL:(NSString*)movieUrl
andSubtitlePath:(NSString*)subPath
withTypeServer:(NSString*)serverType
withName:(NSString*)name
withEpisodeId:(NSString*)episodeId
withFilmId:(NSString*)filmId
withDuration:(NSInteger)targetDuration
withSeason:(NSString*)seasonId;
AFPlayerViewController.m
#synthesize playerViewController;
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (_movieURL) {
self.playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL: _movieURL];
self.playerViewController.moviePlayer.initialPlaybackTime = -1.f;
self.playerViewController.moviePlayer.shouldAutoplay = NO;
[self.playerViewController.moviePlayer setControlStyle:MPMovieControlStyleNone];
[self.playerViewController.moviePlayer setFullscreen:NO animated:YES];
self.playerViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[self.playerViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.playerViewController.view];
[NSLayoutConstraint alightTopBotLeftRight:self.playerViewController.view inView:self.view];
[self.playerViewController.moviePlayer prepareToPlay];
[self.playerViewController.moviePlayer play];
[self receiveNotificationPlayerViewController];
}
}
- (void)receiveNotificationPlayerViewController {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(durationAvailable:)
name:MPMovieDurationAvailableNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(loadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(sourceTypeAvailable:)
name:MPMovieSourceTypeAvailableNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(readyForDisplay:)
name:MPMoviePlayerReadyForDisplayDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didFinishAVideo:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playerViewController.moviePlayer];
}
- (void) durationAvailable: (NSNotification*) notification {
NSLog(#"1");
}
- (void) loadStateDidChange: (NSNotification*) notification {
NSLog(#"2");
if ([self.playerViewController.moviePlayer loadState] != MPMovieLoadStateUnknown) {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
}
- (void) playbackStateDidChange: (NSNotification*) notification {
NSLog(#"3");
switch (self.playerViewController.moviePlayer.playbackState) {
case MPMoviePlaybackStateSeekingForward:
case MPMoviePlaybackStateSeekingBackward:
break;
case MPMoviePlaybackStatePaused: {
NSLog(#"pause");
}
break;
case MPMoviePlaybackStateStopped: {
NSLog(#"stop");
}
break;
case MPMoviePlaybackStateInterrupted:{
NSLog(#"interrupted");
}
break;
case MPMoviePlaybackStatePlaying: {
NSLog(#"playing");
}
break;
default:
break;
}
}
- (void) sourceTypeAvailable: (NSNotification*) notification {
NSLog(#"4");
}
- (void) readyForDisplay: (NSNotification*) notification {
NSLog(#"5");
}
- (void)orientationDidChange: (NSNotification*)notification {
NSLog(#"6");
}
- (void)didFinishAVideo:(NSNotification*)notification {
[self removeNotification];
}
- (void)removeNotification {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMovieDurationAvailableNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMovieSourceTypeAvailableNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerReadyForDisplayDidChangeNotification
object:self.playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:self.playerViewController.moviePlayer];
}
AppDelegate.h
#property (strong, nonatomic) AFPlayerViewController *player;
AppDelegate.m
+ (AppDelegate *)shareInstance{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (UIViewController *)currentVisibleController{
id rootController = self.window.rootViewController;
if ([rootController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootController;
return navigationController.topViewController;
}
if ([rootController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabbarController = (UITabBarController *)rootController;
id topViewController = [tabbarController.viewControllers objectAtIndex:tabbarController.selectedIndex];
if ([topViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navi = (UINavigationController *)topViewController;
return navi.topViewController;
}
return topViewController;
}
return self.window.rootViewController;
}
When I'd like to play a video:
[AppDelegate shareInstance].player = [[AFPlayerViewController alloc] initWithContentURL:link
andSubtitlePath:subtitle
withTypeServer:serverType
withName:nameFilm
withEpisodeId:epObject.episodeId
withFilmId:filmId
withDuration:lastDuration
withSeason:epObject.id_season];
[[AppDelegate shareInstance].currentVisibleController presentViewController:[AppDelegate shareInstance].player animated:NO completion:^{
}];
You may well be getting the error because of notifications being sent to a removed controller object as #Bannings says. Nevertheless, I have a couple of other suggestions that will improve your code (and I am fairly sure will remove the error).
Firstly, the documentation says that you should register for the MPMoviePlayerLoadStateDidChangeNotification and use the loadState method to determine when the movie is ready to start playing. I strongly suggest that you do that.
Secondly, you are instantiating a MPMoviePlayerController every time your view appears. I would suggest that you create a single AFPlayerViewController and a single MPMoviePlayerController. Present the same AFPPlayerViewController whenever you wish to play another movie.
When you first instantiate the MPMoviePlayerController, you will need a a URL, for its init method, but subsequent movies can be started using the contentURL property of MPMoviePlayerController
A side advantage of my suggestion is that it will be very easy for a user to pause a movie, go to a different view, and then quickly resume when they return to the movie view.
Have you called the removeNotification if you try and watch something else? try to add viewDidDisappear:
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self removeNotification];
}
I think I see the real problem here: you should be using MPMoviePlayerController not MPMoviewPlayerViewController. Make that change, and see if the crash disappears. My suggestion about loadState should be followed too.
Related
For some reason, UIKeyboardWillHideNotification is being executed twice in my below code - I haven't a clue as to why. I know this because my NSLog ("Closed!") appears twice in my console. Am I missing something obvious (and no, I don't have UIKeyboardWillHideNotification pasted somewhere in my code a second time).
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillChange:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleKeyboard:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleKeyboard:) name:UIKeyboardWillShowNotification object:nil];
}
- (void)handleKeyboard:(NSNotification*)aNotification{
NSDictionary* info = [aNotification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 3;
[value getValue:&duration];
if (aNotification.name == UIKeyboardWillShowNotification) {
self.upView.frame = CGRectOffset(self.upView.frame, 0, -self.keyboardHeight); self.tableView.frame = CGRectOffset(self.tableView.frame, 0, -self.keyboardHeight);
[self moveCustomView:YES duration:duration];
}
if (aNotification.name == UIKeyboardWillHideNotification) {
/** KEYBOARD HIDE **/
self.upView.frame = CGRectOffset(self.upView.frame, 0, self.keyboardHeight); self.tableView.frame = CGRectOffset(self.tableView.frame, 0, self.keyboardHeight);
[self moveCustomView:NO duration:duration];
NSLog(#"CLOSED!");
}
}
Make sure to remove observers in viewDidDisappear as , view controller may be not reallocated from some reason and code in viewDidLoad is executed twice as observer is added twice
// Objective c
- (void)viewWillDisappear:(BOOL)paramAnimated{
[super viewWillDisappear:paramAnimated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
// Swift
override func viewDidDisappear(_ animated: Bool)
{
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardDidShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
Be sure to remove the observer from the dealloc method. If you do not remove it and its memory is not released, it will listen for keyboard behavior on other pages. In addition, you should not add the same notification twice to the same observer.
Instead of Using same method for Hide and show notification. You can use two different Methods.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
Now, for Change your frame You can use following code
NSDictionary* info = [aNotification userInfo];
CGSize *kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
self.tableView.frame = CGRectOffset(self.tableView.frame, 0, -kbSize.height);
Please, try it like this:
What I did:
• moved subscription to viewWillAppear
• added "unsubscribe" in viewWillDisappear
• added "unsubscribe" in dealloc (shouldn't be related to your issue, but that's the right way to do it still)
• replaced == with isEqual in your handler (also not related to your issue, most likely).
There may be some typos there. Sorry, if that's the case.
-(void)viewWillAppear {
[super viewWillAppear];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillChange:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleKeyboard:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleKeyboard:) name:UIKeyboardWillShowNotification object:nil];
}
-(void)viewDidLoad {
[super viewDidLoad];
//Leaving this method here just to point out that everything was moved to viewWillAppear
}
- (void)handleKeyboard:(NSNotification*)aNotification{
NSDictionary* info = [aNotification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 3;
[value getValue:&duration];
if ([aNotification.name isEqual: UIKeyboardWillShowNotification]) {
self.upView.frame = CGRectOffset(self.upView.frame, 0, -self.keyboardHeight);
self.tableView.frame = CGRectOffset(self.tableView.frame, 0, -self.keyboardHeight);
[self moveCustomView:YES duration:duration];
}
if ([aNotification.name isEqual: UIKeyboardWillHideNotification]) {
/** KEYBOARD HIDE **/
self.upView.frame = CGRectOffset(self.upView.frame, 0, self.keyboardHeight);
self.tableView.frame = CGRectOffset(self.tableView.frame, 0, self.keyboardHeight);
[self moveCustomView:NO duration:duration];
NSLog(#"CLOSED!");
}
}
-(void)unsubscribe {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)viewWillDisappear {
[super viewWillDisappear];
[self unsubscribe];
}
-(void)dealloc {
[self unsubscribe];
}
I'm trying to play a video in mp4 format from URL over HTTPS using MPMoviePlayerController, but video is not playing and I receive an error in logs:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
Is any way to play this kind of video on iOS?
Here's my code:
#import "FirstViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#interface FirstViewController ()
#property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
#end
#implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self playBtnPressed];
}
-(void)playBtnPressed
{
NSURL *url=[[NSURL alloc] initWithString:#"https://....mp4"];
_moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer];
_moviePlayer.controlStyle=MPMovieControlStyleDefault;
//moviePlayer.shouldAutoplay=NO;
[_moviePlayer play];
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDonePressed:(NSNotification*)notification
{
[_moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer];
if ([_moviePlayer respondsToSelector:#selector(setFullscreen:animated:)])
{
[_moviePlayer.view removeFromSuperview];
}
_moviePlayer=nil;
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[_moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayer];
if ([_moviePlayer respondsToSelector:#selector(setFullscreen:animated:)])
{
[_moviePlayer.view removeFromSuperview];
}
}
#end
Probably video aspect ratio issue try setting aspect ratio
[player setScalingMode:MPMovieScalingModeAspectFit];
player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
Or check if the video file is there in the specified URL location
It seems to be an iOS 7 issue.
Apparently, moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; does not work anymore.
For me, replacing it with MPMovieSourceTypeFile solved this error.
Use following code it will work for you. Be sure that you have the notification observer declared before playing movie, as follows:
[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController.moviePlayer];
moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[moviePlayerController.moviePlayer prepareToPlay];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer play];
I am trying to change the mapType from another ViewController but It only displays the HybridType. Any other mapType is not changing whatever the button on my segmented control is pressed. What am I doing wrong? Thank you in advance..
-(void) receiveTestNotification:(NSNotification *) notification{
_mapView.delegate = self;
if ([[notification name] isEqualToString:#"TestNotification"]) {
_mapView.mapType = MKMapTypeStandard;
NSLog(#"Successfully changed maptype");
}
if ([[notification name] isEqualToString:#"TestNotification2"]) {
_mapView.mapType = MKMapTypeSatellite;
NSLog(#"Successfully changed maptype");
}
if ([[notification name] isEqualToString:#"TestNotification3"]) {
_mapView.mapType = MKMapTypeHybrid;
NSLog(#"Successfully changed maptype");
}
}
in ViewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiveTestNotification:) name:#"TestNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiveTestNotification:) name:#"TestNotification2" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiveTestNotification:) name:#"TestNotification3" object:nil];
and in my other viewController:
- (IBAction)segmentedControl:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
[[NSNotificationCenter defaultCenter] postNotificationName:#"TestNotification" object:self];
[self dismissModalViewControllerAnimated:YES];
case 1:
[[NSNotificationCenter defaultCenter] postNotificationName:#"TestNotification2" object:self];
[self dismissModalViewControllerAnimated:YES];
case 2:
[[NSNotificationCenter defaultCenter] postNotificationName:#"TestNotification3" object:self];
[self dismissModalViewControllerAnimated:YES];
}
}
Everythiing seems fine. Check all the iboutlets from the segmented control and log could be more helpful in this case. One other thing you should use break; statement in the switch cases otherwise it goes on executing the code below and so when you want to send TestNotification it will also send other two notifications below.
You miss the "break" in switch / case.
I have an issue with my app..
It's crashing when i'm using home button for multitasking to move to another app and when i want to go back again to my app it's crashing and i get the message:
*** -[UIView convertRect:toView:]: message sent to deallocated instance 0x81e4020
It started since i've implemented "inner-view" ad's.
do i need to do something in my code to make it disspapear?
I tried to solve it but no success.
This is my code of the ad's:
CGRect frame = CGRectMake(0, 480, 320, 50);
self.adBanner = [[UIView alloc] initWithFrame:frame];
[self.view convertRect:adBanner.frame toView:nil]; --->This is a line i tried to put...
[self.view addSubview:self.adBanner];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdReceived:) name:#"iaAdReceived" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaDefaultAdReceived:) name:#"iaDefaultAdReceived" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdFailed:) name:#"IaAdFailed" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdClicked:) name:#"IaAdClicked" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdWillShow:) name:#"IaAdWillShow" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdDidShow:) name:#"IaAdDidShow" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdWillHide:) name:#"IaAdWillHide" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdDidHide:) name:#"IaAdDidHide" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdWillClose:) name:#"IaAdWillClose" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdDidClose:) name:#"IaAdDidClose" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdWillResize:) name:#"IaAdWillResize" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdDidResize:) name:#"IaAdDidResize" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdWillExpand:) name:#"IaAdWillExpand" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAdDidExpand:) name:#"IaAdDidExpand" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAppShouldSuspend:) name:#"IaAppShouldSuspend" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iaAppShouldResume:) name:#"IaAppShouldResume" object:nil];
// Display ad
if (![InneractiveAd DisplayAd:#"iOS_Test" withType:IaAdType_Banner withRoot:self.adBanner withReload:60 withParams:optionalParams])
{
[adBanner removeFromSuperview];
}
}
-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[adBanner removeFromSuperview];
}
- (IBAction)iaAdReceived:(id)sender
{
// The ad view has finished loading a paid ad
}
- (IBAction)iaDefaultAdReceived:(id)sender
{
// The ad view has finished loading a default ad
}
- (IBAction)iaAdFailed:(id)sender
{
// The ad view has failed to load an ad
}
- (IBAction)iaAdClicked:(id)sender
{
// The ad has been clicked
}
- (IBAction)iaAdWillShow:(id)sender
{
// The ad is about to show
}
- (IBAction)iaAdDidShow:(id)sender
{
// The ad did show
}
- (IBAction)iaAdWillHide:(id)sender
{
// The ad is about to hide
}
- (IBAction)iaAdDidHide:(id)sender
{
// The ad did hide
}
- (IBAction)iaAdWillClose:(id)sender
{
// The ad is about to close
}
- (IBAction)iaAdDidClose:(id)sender
{
// The ad did close
}
- (IBAction)iaAdWillResize:(id)sender
{
// The ad is about to resize
}
- (IBAction)iaAdDidResize:(id)sender
{
// The ad did resize
}
- (IBAction)iaAdWillExpand:(id)sender
{
// The ad is about to expand
}
- (IBAction)iaAdDidExpand:(id)sender
{
// The ad did expand
}
- (IBAction)iaAppShouldSuspend:(id)sender
{
// The app should suspend (for example, when the ad expands)
}
- (IBAction)iaAppShouldResume:(id)sender
{
// The app should resume (for example, when the ad collapses)
}
I attached a screenshot...
What could it be?
Thanks...
Your problem is that when running :
[self.view convertRect:adBanner.frame toView:nil];
your view doesn't exists anymore.
in your appDelegate you should work on this method :
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
anyway, what did you try to achieve with this line ? because it's returning a CGRect which you're not using.
In MPMoviePlayerController, when ever the controls disappear, even the status bar is disappearing with it. Since i want the status bar to appear even when the control disappears, i placed the below code
[[UIApplication sharedApplication] setStatusBarHidden:NO];
But the above code is not making any difference, teh status bar is getting disappeared along with the player controls. How to solve this problem.
Please find the code below, and let me know how to rectify it.
- (void) readyPlayer {
mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if ([mp respondsToSelector:#selector(loadState)])
{
// Set movie player layout
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setFullscreen:YES];
// May help to reduce latency
[mp prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePreloadDidFinish:) name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
object:nil];
}
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
NSLog(#"moviePlayerLoadStateChanged");
// Unless state is unknown, start playback
if ([mp loadState] != MPMovieLoadStateUnknown)
{
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// Rotate the view for landscape playback
[[self view] setBounds:CGRectMake(0, 0, 768, 1000)];
// Set frame of movieplayer
[[mp view] setFrame:CGRectMake(0, 0, 768, 1000)];
// Add movie player as subview
[[self view] addSubview:[mp view]];
// Play the movie
[mp play];
}
}
- (void) moviePreloadDidFinish:(NSNotification*)notification {
// Remove observer
NSLog(#"moviePreloadDidFinish");
[[NSNotificationCenter defaultCenter] removeObserver:nil
name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// Play the movie
[mp play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSLog(#"moviePlayBackDidFinish");
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self dismissModalViewControllerAnimated:YES];
}
This is a well-known issue of MPMovieControlStyleFullscreen. Simply use the MPMovieControlStyleEmbedded controlStyle and you are good to go.
And, by the way, that is the more adequate controlStyle for embedded usage anyways.