Is it possible to have two different playback notifications in a MPMoviePlayerController?
I want to use these:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(MPMoviePlayerPlaybackDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.moviePlayer];
i did manage to get them working but when i use them together only MPMoviePlayerPlaybackStateDidChangeNotification is called.
Please advise.
Related
I have use below for for register notification:-
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(AllSearch:) name:filter object:nil];
-(void)AllSearch:(NSNotification *)notification
{
NSLog(#"abc");
}
and i post notification with this code:-
[[NSNotificationCenter defaultCenter] postNotificationName:filter object:nil];
But "AllSearch" Method not calling.
plz check you code you have to addObserver first
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(AllSearch:) name:filter object:nil];
befor postNotification
[[NSNotificationCenter defaultCenter] postNotificationName:filter object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
UIMoviePlayerControllerDidExitFullscreenNotification NSNotification not working in iOs 8
i am also faced the same problem but finally ended with using UIWindowDidBecomeVisibleNotification and UIWindowDidBecomeHiddenNotification, for embedded youtube videos(assuming by looking at your selector method names)
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(enteredFullScreen:) name:UIWindowDidBecomeVisibleNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(exitedFullScreen:) name:UIWindowDidBecomeHiddenNotification object:nil];
above is a patch work around,(hope this helps)
I use MPMoviePlayerController and it works fine. I guess that depending what you are using it for, you don't need UIMoviePlayerController.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(youTubeFinished)
name:MPMoviePlayerDidExitFullscreenNotification
object:self.player.moviePlayer];
I'm developing a little game and I'm using AVAudioPlayer in order to play the game's background music. The problem is that if the user exits the app without closing it in the app drawer (so it is in the background) the music will not stop. How can I change this? Thanks for your help!
In the ViewController where you handle your AVAudioPlayer add this in your viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(appWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
Then you add those 2 methods :
-(void) appWillResignActive:(NSNotification*)note{
NSLog(#"App is going to the background");
// This is where you stop the music
}
-(void) appWillTerminate:(NSNotification*)note{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
NSLog(#"App will terminate");
}
The quick answer here is that you want to configure the AVAudioSession to use the category AVAudioSessionCategorySoloAmbient.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];
This before you activate the session of course.
In my application I am loading some webpages embedded with Photos and Videos. Also I am using the following notifications to manage the player,
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(embeddedVideoStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(embeddedVideoEnded:) name:#"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
This is working fine in iOS7, but in iOS8 its not working. Any workarounds? Thanks in advance.
This is one option, I have found.. The problem is that is not Will is DID become hidden..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(embeddedVideoStarted:)
name:UIWindowDidBecomeVisibleNotification
object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(embeddedVideoEnded:)
name:UIWindowDidBecomeHiddenNotification
object:self.view.window];
If, I find a fix for the second notification I will posted it.. :)
I wanted to run a instance method from my BPGameController class called "pauseGame" in my app delegate when my application enters background mode and when it resigns, and a instance method called "resumeGame" when the application becomes active again, I've tried a few different things but none have worked for me so far
In BPGameController's viewDidLoad method sign up for the notifications as follows:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(pauseGame)
name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(resumeGame)
name:UIApplicationDidBecomeActiveNotification object:nil];
When you are done remove yourself from observing.
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];