iOS 8 MPMoviePlayerPlaybackDidFinishNotification not working - ios8

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

Related

_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).

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...

iOS MPMoviePlayer (resume playback after app become Active)

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!

xcode Trying to embed Video. No errors but no video either

I am sure I am just missing something stupid but I have been stuck on this all day. Any help would be appreciated. I was trying to embed video in an ipad app. I am using xcode 4.2.5. I am following a tutorial which I found here: embeded ipad video
I have followed the instructions exactly as far as I can tell. I have started over several times. Before I was getting a memory error but this time I am not getting any errors at all. Only no video or audio. The only part of the tutorial I did not use was the last part about the ipad rotation because I'm not worried about that.
The only part I was unable to follow exactly was putting the video in the resources folder because xcode 4.5.2 does not make one. So I put MOVIE.MOV in the same directory as my .h, .m and .xib files were automatically placed in. I have tested the video and it does work on its own.
Here is the code: any help or guidance would be appreciated. Sorry for being such a NOOB.
the header:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController{
}
-(IBAction) playMovie;
#end
the main:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)playMovie
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"MOVIE" ofType:#"MOV"]];
MPMoviePlayerController *moviePlayer =
[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer
respondsToSelector:#selector(setFullscreen:animated:)])
{
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
}
Thankyou very much for any help.
Some things you could check:
Did you check the "Copy item to destinations group folder" when you dragged the movie onto the Xcode project?
Does the item show up in the "Copy Bundle Resources" Build Phase? (click on the Project, Select your target and check the "Build Phases" tab in Xcode)
Paths strings are case-sensitive on iOS. Does your movie really have the file name "MOVIE" and the extension "MOV" (all upper-case)?

NSWindowDidBecomeMainNotification firing for ALL windows

I have an app with two windows - a main window, and a preferences window which can be opened from the menubar. I am trying to implement a notification that the preferences window becomes the main window so that I can update it when it is opened, however my notificaton is firing whenever any window opens, even a different window.
inside my PrefsWindowViewController.m awakeFromNib I have:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didBecomeMain:)
name:NSWindowDidBecomeMainNotification
object:nil];
And in my PrefsWindowViewController.m dealloc, I have:
[[NSNotificationCenter defaultCenter] removeObserver:self name: NSWindowDidBecomeMainNotification object:nil];
Can anybody explain why this might get called when a different window besides my PrefsWindow becomes the main window?
It's because you're passing nil for the object: parameter. Pass your preferences window instead, or check [notification object] == yourPrefsWindow in your callback.

Resources