Is there any public api to detect AirPlay available or not - ios

I have implement the MPVolumeView to show Airplay option but I don't know how to hide MPVolumeView if Airplay options/sources are no longer available.
Is there any public API which can detecting AirPlay option/source are available or not. So that application can hide/show the airplay option.
NOTE: I am using custom player not the default MPMoviePlayerController
Thanks!

I see two approaches that would work:
Set MPVolumeView's showsVolumeSlider to NO and the AirPlay route button picker "...is visible only when there is an AirPlay output device available."
Source: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AirPlayGuide/EnrichYourAppforAirPlay/EnrichYourAppforAirPlay.html
Add observer for MPVolumeViewWirelessRoutesAvailableDidChangeNotification and hide or remove your subview.
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleWirelessRoutesDidChange:)
name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)handleWirelessRoutesDidChange:(NSNotification *)notification {
NSLog(#"Wireless routes did change: %#", notification);
// Hide or remove your MPVolumeView
}

In addition to the correct response the MPVolumeViewWirelessRoutesAvailableDidChangeNotification it's been deprecated for this one AVRouteDetectorMultipleRoutesDetectedDidChangeNotification

Related

How to get YTPlayer Done button state in ios?

I am using YTPlayer for playing youtube video. video is playing correctly but when i click on Done button which method is call?
-(void)playerView:(nonnull YTPlayerView *)playerView didChangeToState:(YTPlayerState)state;
This method invokes when you click on done, pause etc.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(closedFullScreen:) name:UIWindowDidBecomeHiddenNotification object:nil];
-(void)closedFullScreen:(NSNotification *)myNotification{
[self.playView pauseVideo];
//required stuff here like dismissing your AVFullScreenViewController
}

stop background music when embed video start in iOS

i am using UIWebView to play embed video from youtube, and my problem is how can i call a method when the embed video starts to play?
i found the solution myself so if anyone want it here it is:
in - (void)viewDidLoad add:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoStrated:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
and add:
-(void)videoStrated:(NSNotification *)notification
{
NSLog(#"video started");
}
in implemention file

Enable UIButton after UIImagePicker is presented

I have tried everything or at least I think I have.
I am presenting a custom UIImagePicker with a shutter UIButton disable.
This UIButton is only enable when my view controller receives a notification telling that the camera is ready.
This method is being called; however, when I set the UIButton to enable nothing happen. The button is there because I can touch it but I cannot see it.
Here is a piece of code:
- (void)viewDidLoad
{
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(cameraIsReady:) name:AVCaptureSessionDidStartRunningNotification object:nil];
}
- (void)cameraIsReady:(NSNotificationCenter *)notigivation{
NSLog(#"Camera is ready");
[self.shutterButton setEnable:YES];
[self.shutterButton setNeedsDisplay]; //I tried with and without this method.
}

MPMoviePlayerController seek forward button stops the video in IOS7?

I am facing an issue with MPMoviePlayerController in iOS 7. When i single tap on the forward seek button the video stops and not allow to do anything like to play again full screen and slider change.
Here is my code.
remove the Observer for the MPMoviePlayerPlaybackDidFinishNotification
[[NSNotificationCenter defaultCenter] removeObserver:moviePlayerViewController name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerViewController.moviePlayer];
and add New Notification MPMoviePlayerPlaybackDidFinishNotification
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
Here is my custom method to handle the MPMoviePlayerPlaybackDidFinishNotification
-(void)videoFinished:(NSNotification*)aNotification{
MPMoviePlayerController *moviePlayer = [aNotification object];
NSLog(#"%f",moviePlayer.currentPlaybackTime);
int reason = [[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
}else if (reason == MPMovieFinishReasonUserExited) {
[self performSelector:#selector(dismiss:) withObject:aNotification afterDelay:0.5];
}else if (reason == MPMovieFinishReasonPlaybackError) {
}
}
I need to stop this strange behaviour on single click and continue to play.
Anyone know how to do this?
Thanks.
I think there are no any notifications or event are available on user
interaction with the standard player buttons, and i have to implement
own UI for the player controls. by this way we can then determine the
actions for a single touch, long touch, etc. Then, we can add whatever
functionality like increasing the play rate, or simply seeking to a
time.

Can UIWebView catche the event caused by pressing the MediaPlayer's done button

I want to use UIWebView to load URL and play vedios. When I press done button in MediaPlayer control on the UIWebView, I want to do something.
My Question is, in this case can it be OK, or does the UIWwebView has a delegate method to do after pressing done button?
The "Done" button only shows up in full screen mode. You can detect the end of full screen mode by observing the #"UIMoviePlayerControllerDidExitFullscreenNotification" mode:
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullscreen:)
name:#"UIMoviePlayerControllerDidExitFullscreenNotification"
object:nil];
}
- (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)moviePlayerDidExitFullScreen:(NSNotification *)notification
{
// This is where you do whatever you want because the user pressed "Done".
}
The UIMoviePlayerControllerDidExitFullscreenNotification is not documented, so I don't know if it will pass App Store review. If you're not planning to distribute via the App Store, it shouldn't matter.

Resources