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
Related
I want to play a video in seprate view controller, where I can Play/Pause or dismiss that view controller. In my case, I recorded the video in my app and calling this delegate method in order to save this video in assets, but I want to play it first before using the ALAssetsLibrary.
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
fromConnections:(NSArray *)connections
error:(NSError *)error
And the TEMO URL im getting is :
file:///private/var/mobile/Containers/Data/Application/EA6D31AC-6CC3-4BDF-B874-BC6F30BA5677/tmp/output.mov
How can I play this video in next view controller or in same view controller??
My try:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:outputFileURL];
player.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:player.view];
[player play];
PS: This is showing a black screen area but not actually playing this video.
I had the same problem a few days ago. It ends up that I was calling play method to soon, before the video become ready to play. So, add this before call [player play]. This will notify whenever your video become read to play in MPMoviePlayerController.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
Then setup the observer:
- (void)videoPlayBackDidFinish:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
This worked for me.
Hope it helps.
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
}
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.
I have a MPMoviePlayerController that streams video. The problem is that the video and audio work fine in the simulator, but on the device, the view just turns black and no audio or video comes out. Here is my code:
- (IBAction)playVideoPress:(id)sender
{
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
_mpPlayer3 = player;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(moviePlayerDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
_mpPlayer3.controlStyle = MPMovieControlStyleDefault;
[_playerView3 addSubview: _mpPlayer3.view];
[_mpPlayer3.view setFrame:_playerView3.bounds];
[_mpPlayer3 play];
}
Then the notification when the video finishes is:
- (void)moviePlayerDidFinish:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
NSLog(#"Did Finish Notification");
[_mpPlayer3 stop];
_mpPlayer3 = nil;
}
This works fine in the simulator, but just shows a black screen in the view I want to display the video in. Another weird thing that happens is that when I do run it in the simulator, I get a bunch of errors such as:
Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
I don't know if that has anything to do with the simulator playing the video and the device not, but I thought that I would mention it here.
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.