I'm currently showing a dailymotion url directly into a UIWebview.
When tapping on the thumbnail image, the video starts playing in fullscreen mode.
The problem is: when the video stops playing or the user tapps the "done" button, the original thumbnail has disapeared from the UIWebview, making it impossible to launch the video again.
I would like to control when the video has finished playing or the user has tapped the done button to reload the UIWebView.
I've been looking around and playing with the Notification center but I couldn't get any response, can you tell me what code I should use ?
loading the video
NSURLRequest *requestObject = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.dailymotion.com/embed/video/xh7cgv_cine-pocket-a-candidate_creation"]];
[self.webv loadRequest:requestObject];
notification catch
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullscreen:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidEnterFullscreenNotification:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
thanks,
Louis
corresponding to this thread the MediaPlayer doesn't send out any notifications when started from within the UIWebView (no source given however). you could try these hacks: visible-hidden events hack, timed key window checking-hack, subview events-hack. If you had luck, please share some code!
Related
I have an application, and this application open an url in Safari. But if the user tap on the top left button to return to my app how can i catch this event?
For this case, the solution is to view controller register for the UIApplicationWillEnterForegroundNotification notification. When this notification is sent, you can do the stuff needed.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(doSomeStuff) name:UIApplicationWillEnterForegroundNotification object:nil];
-(void)doSomeStuff
{
//handle what you needed
}
I have a split view based app, and would like to listen for some sort of notification for when the root menu is displayed. The reason I want to do this is because the keyboard overlaps the menu, so I would like to hide the keyboard when the menu is displayed.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:<Some Notification Here>
object:self.view.window];
I already have the method to hide the keyboard, I'm just looking for the appropriate notification.
Thanks!
you can post the notification yourself from the root menu. Just subclass it and post the notification on viewDidAppear or viewWillAppear.
The word of warning: if you are targeting iOS 5 and up you should kep in mind the viewWillAppear and viewDidAppear are deprecated in iOS6. use
willMoveToParentViewController or didMoveToParentViewController or -(void)viewWillLayoutSubviews
-(void)willMoveToParentViewController:(UIViewController *)parent{
if (!parent)
//post notification here
}
Also, you can provide nil as a notification name and listen to any possible notification, then NSLog it out, perhaps you can find a useful notification there, just make sure it is documented to futureproof your product.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(notificationReceived:) name:nil object:nil];
In applications like Foursquare when I click the Home button the application goes to background. Then when I click on its icon, it loads back the content on the screen.
When I send my app to background and then I recall it back, it doesn't load back the content to the screen. I have entered my code in the viewDidAppear method but it is not executed.
How is it possible to load the application content when it becomes active?
You need to respond to - (void)applicationDidBecomeActive:(UIApplication *)application or - (void)applicationWillEnterForeground:(UIApplication *)application or the equivalent UIApplication notifications. The UIViewController lifecycle calls like viewDidAppear aren't triggered by app lifecycle transitions.
smparkes suggestion is right. You could register for UIApplicationDidBecomeActiveNotification or UIApplicationWillEnterForegroundNotification. These notifications are called after those method (the ones smparkes wrote) are called. In the handler for this notification do what you want. For example in viewDidLoad for your controller register the following notification:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doUpdate:)
name:UIApplicationDidBecomeActiveNotification object:nil];
Do not forget to remove in dealloc:
[[NSNotificationCenter defaultCenter] removeObserver:self];
Finally, doUpdate method could be the following
-(void)doUpdate:(NSNotification*)note
{
// do your stuff here...
}
I suggest you to read UIApplicationDelegate class reference. In particular read about Monitoring Application State Changes.
Hope it helps.
Suppose you want to listen to UIApplicationDidBecomeActiveNotification,here is the ObjC code that might help you.
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
// custom code goes here.
}];
I am calling
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
method in viewDidLoad, but keyboard dos not appearing when i click on web view.
can anybody tell me why is this happening
You can't make the keyboard show up be calling anything on the notification center. You need an UI element that can handle text input (for example an UITextField, a UIWebView can't handle text input by itself) and than call
[textField becomeFirstResponder]
movieURL = [NSURL URLWithString:#"http://122.165.71.249:6060/test/music/killbill.mp3"];
// Setup the player
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
I am using this code play online connection ,but i want offline also play in the video url link.
You will have to use an NSURLConnection to download the file yourself, you can then use the original URL for the movie player whilst downloading the video at the same time. When I did this I tried to get the video player to use the local file before I has finished, by delaying start of playback after a certain number of bytes have been received, but I found it would only work on the simulator but not on the actually iPhone/iPodTouch. If you do search for (MPMoviePlayerViewController "Nathan Day" Cache) you will see some example code I post on Apples Cocoa mailing trying to solve this.