I am loading a page in UIWebView. The page contain thumbnails to play. When I click any of the thumbnails, it launches in any default player. I want it should not play in default player, I want to play the video in MPMovieController With Custom controls whenever I click on the thumbnail in UIWebview. Could I stop the videos to play in default player??
This would require to get the movie url and play it in MPMoviePlayer and stop the redirection of webview.
LOGIC:
in webview's delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
get the URL from NSURLRequest's NSURL and then get the redirection url with NSURL absoluteString
compare the extension of the file in url. if it is of video e.g. .mov/.mp4,
load your MPMoviePlayer with the URL to play it in your application and return NO; for this delegate method.
If you have access to thumbnail code you can put javascript method which will do simple redirect:
<a href="#" onClick="javascript:play_native_video_url(url); >thumbnail here</a>
play_native_video_url(url) {
window.location = "play://"+url;
}
UIWebView delegate will catch this redirect with custom scheme (not http:):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// Define if it is your custom scheme:
if ([request.URL.host isEqualToString:#"play"]) {
// get url and play it with native MPMoviePlayer...
return NO; // do not let WebView process it
}
}
written from memory
Related
**Situation is like this,my webview load a base request url,when user clicked the html or anyother action,the webview will laod a new url. Can I get the webview changed events? If window.location.href can be worked well,and how?
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
this method will be performed every time you click the button of html
I've UIWebView with webpage loaded. This webpage is simple - one picture which follows somewhere
How can I receive this URL after taping for handling in xcode? I don't want to open this link in the same web view(what is happened now). Thanks for any tip.
Use this delegate function.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL *regURL=[request URL];
NSString *urlString=[regURL absoluteString];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//my code
}
Currently my above delegate method is called, once i touch inside in my webview.
So i want to know what is the difference between following 2 navigationtype: UIWebViewNavigationTypeOther & UIWebViewNavigationTypeLinkClicked.
Because some of the URL on selection provides navigation Type as UIWebViewNavigationTypeOther & some provide UIWebViewNavigationTypeLinkClicked.
From the apple document i cannot able to clear my self.
UIWebViewNavigationTypeLinkClicked happens if the user taps a <a href=""> style link, if the change is done from within Javascript (onclick event for example) UIWebViewNavigationTypeOther is used.
Furthermore UIWebViewNavigationTypeOther is used if you first load a page or you'll be redirected by a meta refresh or something
I am trying to build a simple app that uploads images to my site. I am using this tutorial:
http://www.youtube.com/watch?v=aQXaJO36I7Y
What I want to do instead of using a button from the app's interface I wan to use a button within a website in a webview. So I want a button to call the opening of the photo album to select a image to upload.
Basically I need a way for a javascript function to call a action in the app itself.
How can I do this?
You could just use a custom link, which you can then detect in the UIWebViewDelegate method.
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *rawURL = [[request URL] absoluteString];
if([rawURL isEqualToString:#"callImageLib://"]) {
[self methodeForImageLib];
}
return NO;
}
return YES;
}
If i understand it correctly you need to communicate iPHone Web application to call native iPhone application and visa versa. please check the following links.
http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript
http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview
hope these 2 link help to solve your issue.
I have an application that acts like an internet browser for one webpage. If the webpage is in one view, can I have it act so when a specific URL is selected that it will open the URL in a different view?
Yes. In your webViewController, implement this
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
Check to see if it's the url you're interested in, then create and push a view that displays the web page.
Oh, and return NO to prevent the load from occurring in this view.