How to get YTPlayer Done button state in ios? - 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
}

Related

Is there any public api to detect AirPlay available or not

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

How to call Done button of mpmovieplayer without touch or click of Done button on screen in ios?

How to call Done button of mpmovieplayer without touch or click of Done button on screen in ios ?
I mean how to access or call Done button manually after declare of notification.
like this....
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
- (void)willExitFullscreen:(NSNotification*)notification{
NSLog(#"willExitFullscreen");}
so here how to call exitedFullscreen. ?

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

How to stop MPMoviePlayerViewController's automatic dismiss on moviePlaybackDidFinish?

An MPMoviePlayerViewController which is presented modally through presentMoviePlayerViewControllerAnimated: automatically dismisses itself when it's content finishes playing.
I've tried to disable this, since I want to play other content afterwards. However, even if I register to the NSNotificationCenter with [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; and set some other content, it still dismisses.
How can I stop MPMoviePlayerViewController from automatically dismissing itself?
UPDATE:
As a clarification, this question is only about removing the automatic dismissal and not about dealing with the disabled 'done' button. The selected answer reflects. This is by design, since we assume the developer adds their own means of dismissing the MPMoviePlayerViewController. However, #bickster's answer deals with the 'done' button as well.
Thanks to this blog article I figured out that MPMoviePlayerViewController automatically registers itself to the NSNotificationCenter upon creation. You have to first remove this registration and it will stop dismissing itself automatically.
// Initialize the movie player view controller with a video URL string
MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease];
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:playerVC name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer];
You can use this code to stop the viewcontroller from automatically dismissing and capture the event when the user clicks the "Done" button so you can dismiss the viewcontroller yourself.
Step 1. - alloc a MPMoviePlayerViewController
videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[[NSURL alloc ]initWithString:[aURL];
Step 2. - Remove the default MPMoviePlayerPlaybackDidFinishNotification observer and add your own
[[NSNotificationCenter defaultCenter] removeObserver:videoPlayer
name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer];
Step 3. - Present viewcontroler
[self presentMoviePlayerViewControllerAnimated:videoPlayer];
Step 4. - Add videoFinish: method
-(void)videoFinished:(NSNotification*)aNotification{
int value = [[aNotification.userInfo valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (value == MPMovieFinishReasonUserExited) {
[self dismissMoviePlayerViewControllerAnimated];
}
}
You can try something like this.
when the mpmovieplayercontroller finishes playing a video and you recieve the notification in your method movieFinishedCallback: implemect
[playerVC.movieplayer setContentURL:// set the url of the file you want to play here];
[playerVC.moviePlayer play];
Hope this helps
Since "Done" button is not working anymore if I remove MPMoviePlayerPlaybackDidFinishNotification from NSNotificationCenter, I change repeat mode to MPMovieRepeatModeOne.
Then, everything's working fine except the video is repeated.
MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease];
[playerVC.moviePlayer setRepeatMode:MPMovieRepeatModeOne];

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