iOS MPMoviePlayer (resume playback after app become Active) - playback

I have App, playing Videos from web
everything works fine
but when user leave the app for reading email or anything
and come back the player gone!! big problem
so, I want user resume watching after come back to app
here is my code so far
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterforground) name:UIApplicationWillEnterForegroundNotification object:nil];
the Methods
- (void) didEnterBackground
{
[theMovie.moviePlayer pause];
NSLog(#"Playing pause");
}
- (void) didEnterforground
{
[theMovie.moviePlayer play];
NSLog(#"Playing resume");
}
for know I use [self presentMoviePlayerViewControllerAnimated:theMovie]; NOT playing in view
should that's code works but, nothing works
Please Help
Thanks in advance

The answer is very simple, edit info.plist.
Add background competence, required background modes, set category App plays audio
Try it!

Related

Check if there are nspopover opened before creating new one

I have in my code some functionality to open a popover anytime an event happens. Problem is that if those events happen one after the other the popovers opened are overlapped.
I would like to close one popover when opening new one.
Is there any way to get from nswindow if there is an active popover?
Thanks in advance and regards
I think you need play with NSPopover's notification methods such as:
- (void)popoverDidShow:(NSNotification *)notification;
- (void)popoverWillClose:(NSNotification *)notification;
And add some logic which will hide not closed popover...
Finally I was able to figure it out by using notifications posted:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(popoverWillShow:)
name:NSPopoverWillShowNotification
object:nil];
And then in the selector I compare the objects: (popover is an NSPopover)
- (void)popoverWillShow:(NSNotification *)notification {
if (![popover isEqual:[notification object]])
[self close];
}

_UIImagePickerControllerUserDidCaptureItem not called xcode 6

Is it just me or _UIImagePickerControllerUserDidCaptureItem notification from uiimagepickercontroller stopped working on iOS 8 and XCode 6. I use it to rotate the camera overlay after the user taked a picture.
PLease help
It's pretty strange, but in iOS 8 setting observer using
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(imagePickerControllerDidCapture) name:#"_UIImagePickerControllerUserDidCaptureItem" object:nil];
doesn't work for UIImagePickerController, but using block works fine:
self.imagePickerControllerDidCaptureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:#"_UIImagePickerControllerUserDidCaptureItem" object:nil queue:nil usingBlock:^(NSNotification *note) {
[self removeCameraOverlay];
}];
Please notice that in this approach you should store observer object to detach it later using
[[NSNotificationCenter defaultCenter] removeObserver:imagePickerControllerDidCaptureObserver];
In situations like that it very useful to use
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(#"Notification: %#", note.name);
}];
to monitor all notifications, see names and moments it fires.
I also see the same issue with iOS 8 but using block works as mentioned by Amoneron in his answer.
Here's how to do it in Swift:
NSNotificationCenter.defaultCenter().addObserverForName("_UIImagePickerControllerUserDidCaptureItem", object:nil, queue:nil, usingBlock: { note in
// do something here
})
It still works for me, though I am using the notification center for that.
NSNotificationCenter.DefaultCenter.AddObserver (new NSString ("_UIImagePickerControllerUserDidCaptureItem"), HandleUserCapturedItem);
the code is in c# as I am using xamarin to develop, there should be something similar in objective-c since I'm basically using wrapper classes (built by xamarin).

iOS 8 MPMoviePlayerPlaybackDidFinishNotification not working

I used Xcode 6 with iOS 8 SDK.
If the video can't played, when starting MPMoviePlayer. MPMoviePlayerPlaybackDidFinishNotification not working.
I reference this article:
[How to get an error description when playback fails on MPMoviePlayerController
but iOS8 doesn't work.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(MPFinished: ) name:MPMoviePlayerPlaybackDidFinishNotification object:self.MoviePlayer];
How to do that can solve this problem? Thanks.
I had same issue and the only solution I found was to replace the MPMoviePlayerController by a AVPlayerViewController (available since iOS 8 in the AVKit framework).
Make sure the "object" parameter is of class MPMoviePlayerController and not MPMoviePlayerViewController.
If self.MoviePlayer is a MPMoviePlayerViewController, just change this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(MPFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.MoviePlayer];
to this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(MPFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.MoviePlayer.moviePlayer];
The object sending the notification is self.MoviePlayer.moviePlayer

Warning: Attempted to present * whose not in the window hierarchy

I have tried to deal with this issue for too long. Please give me any of your thoughts.
I am presenting a View Controller from an SKScene by sending a Local Notification. [[NSNotificationCenter defaultCenter] postNotificationName:#"closeScene" object:nil];
The notification is handled in the beginning view controller.
- (void)viewDidLoad{ [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(closeScene) name:#"closeScene" object:Nil];
[super viewDidLoad];}
Then:
-(void)closeScene {
//Remove the SKView, or present another viewController here.
constructionViewController *view = [[constructionViewController alloc] init];
[self presentViewController:view animated:YES completion:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"closeScene" object:nil];
}
And every time the notification is sent, I get the warning:
Warning: Attempt to present <constructinoViewController: 0x10ae64160> on <constructinoViewController: 0x10ab329d0> whose view is not in the window hierarchy!
Any help would more than appreciated. Thank you in advance!
When is closeScene called, exactly - before or after viewDidAppear gets called?
The error you're seeing usually happens when you try to present a view controller before the parent is actually displayed on screen. Typically this is because you've called presentViewController before the parent's viewDidAppear method has been called.
Try adding a logging statement to viewDidAppear and see whether it appears in the logs before or after your 'view is not in the window hierarchy' error. If it appears after you'll know what the problem is, and how to fix it (make sure presentViewController is only called after the parent view controller has been displayed). If it's before you probably have an altogether different problem...

Why is QTMovieLoadStateDidChangeNotification not firing?

I'm seeing that setting up a notification on QTMovieLoadStateDidChangeNotification has no effect and the target selector never gets called. Am I missing something?
In awakeFromNib:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieLoadStateDidChange:)
name:QTMovieLoadStateDidChangeNotification
object:nil];
On loading movie:
NSNumber *num = [NSNumber numberWithBool:YES];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
url, QTMovieURLAttribute,
nil];
self.mQTMovie1 = [[QTMovie alloc] initWithAttributes:attributes
error:&error];
Also
- (void)movieLoadStateDidChange:(NSNotification *)notification {
NSLog(#"movieLoadStateDidChange got called");
}
I'm not sure this is the answer but I've encountered this before. The cause in my case was a file whose codec was supported only by a third-party plugin (Flip4Mac in my case).
The load state notification isn't called until the movie finishes after it auto-plays (to nowhere). For long media files, it effectively looks like the notification is never called, since we rarely wait 5 minutes or an hour for a load notification when testing our code. To the user, it looks like the app simply isn't loading the file.
Having the user disable the plugin's auto-play-on-load in System Preferences resolves the issue but unfortunately this one support FAQ I can't get around since users of the app in question frequently use Flip4Mac to support files from common digital voice recorders.

Resources