Loading a document into a Webview - iphone

Am trying to load a .docx file into the uiwebview and am displaying it.To load the document into the webview it takes some fraction of seconds so i can see a white blank screen before the content can appear on the screen.I don't want to see that white screen while loading instead of that i want to do some actions like activity indicator or changing the background.How can i achieve this please help me.
Here is my code;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews
{
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
isWebviewLoaded=YES;
webView.delegate=self;
webView.alpha=0;
NSString *path = [[NSBundle mainBundle] pathForResource:#"SKIN ADVISORuser_updated.docx" ofType:nil];
//NSString *path = [[NSBundle mainBundle]pathForResource:#"UserGuidelines3.html" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViews loadRequest:request];
}
and in viewdidload am calling above method:
[self loadDocument:#"ADVISORuser_updated.docx" inView:self.webView];
Even am implementing a delegate method to change the background but delegate is not executing
- (void)webViewDidFinishLoad:(UIWebView *)webViewload {
if (isWebviewLoaded)
{
isWebviewLoaded = NO;
webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"Instructions Screen Background light_PNG.png"]];
[UIView beginAnimations:#"webView" context:nil];
webView.alpha = 1.0;
[UIView commitAnimations];
}
}
Please can anyone help me..

before loadRequest u could create UIActivityIndicator object and start it by calling start method
and in webView delegate didFinishLoading: & didFailwithError method suspend the activity indicator

- (void)webViewDidFinishLoad:(UIWebView *)webViewload {
will be called only if you have set the delegate for the webView (in the xib &.h file)

Related

Get notification when play button appears in embedded video with UIWebView

i'm using webviews into my app to embed videos, in this way
NSString *embedHTML = #"<iframe width=\"300\" height=\"250\" src=\"http://www.youtube.com/.....\" frameborder=\"0\" allowfullscreen></iframe>";
NSString *html = [NSString stringWithFormat:embedHTML];
[_webView loadHTMLString:html baseURL:nil];
I'd like to get notified when the play button appears, in order to create and stop an activity indicator... I've used
- (void)webViewDidFinishLoad:(UIWebView *)webView
but it's not sufficient... when the webview finishes loading and the activity indicator stops, the playbutton appears 2-3 seconds later...
How can i synchronize the activityindicator stop with the playbutton appearance?
Thanks

Youtube video in UIWebview not working

Using this code to play YouTube video in UIWebView
- (void)embedYouTube {
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
// iframe
videoHTML = [NSString stringWithFormat:#"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"560%%\" height=\"315px\" src=\"%#\"http://www.youtube.com/embed/j9CukQje2qw\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
}
When i click on this LaunchVideo UIButton all it shows black screen on iOS device
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/j9CukQje2qw";
WebViewController *webViewController = [[[WebViewController alloc] initWithNibName:nil bundle:nil] autorelease];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
webViewController.videoURL = self.videoURL;
[self presentModalViewController:webViewController animated:YES];
}
If anyone can point out what i m missing or doing wrong in this code. Why youtube video is not showing. Not using interface builder doing programmtically. Got this project code from web. Tried this project code on ios device it works fine for that project but when applied its code in my project then it is not working. Only difference that his projectcode from web uses interface builder and i am doing it programmtically.I dont get it.
Please help what is wrong with this code.
Thanks for help.
Here is another way to load the youtube video into your app. First, put a UIWebView into your interface and size it to how big you want the video should show (there will be a button to make it full screen), then make an IBOutlet to it, so you can change its properties of hidden (to make it pop up and go away) Here is some code. In the code there is a method used called webviewshow, this calls a simple method that basically just says
webview.hidden = NO;
webviewbutton.hidden = NO;
Then there is a button that also pops up that makes the web view go away when tapped. Here is the code to load the youtube video into the web view
// Create your query ...
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/j9CukQje2qw];
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Now create the URL string ...
NSString* urlString = searchQuery;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView loadRequest:request]; currentTimer= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(webviewshow) userInfo:nil repeats:NO];;
It waits 2 seconds (usual wait time for most connections) until the web view is shown, so the page is loaded and the user does not have to watch it load.
Then when you want to make the video go away, make a method to close the web view like so
- (void) makewebviewGoAway {webview.hidden = YES; webviewbutton.hidden = YES;}
Hopefully, that was helpful. IF you need further help or explanation, just comment off of this.

iOS - Force full screen video

I'm using a MPMoviePlayerViewController. When the video loads and starts playing it doesn't fill up the whole screen. I have to press the full screen button at the top right to make that happen. If I use MPMoviePlayerController I can't get it to fill the screen at all.
Any way via code that I can get my video full screen using the MPMoviePlayerViewController without having to press the fullscreen button?
I know i'm using a private API here, but thats ok, it is for a demo.
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"phatpad" ofType:#"mov"];
if (moviePath)
{
NSURL *url = [NSURL fileURLWithPath:moviePath];
player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
}
player.view.frame = self.view.frame;
[self.view addSubview: player.view];
}
Here is a screen. The first is without pressing the full screen button, the second is after pressing it.
You have to set the fullscreen attribute to true and the scallingMode to the aspect fill like this:
if (moviePath)
{
NSURL *url = [NSURL fileURLWithPath:moviePath];
player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
player.moviePlayer.fullscreen = YES;
player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
}
I have tested at home and it works, so I hope to you too.
On iPhones and iPod Touches, MPMoviePlayerController plays in full screen no matter what, so I'm assuming you're talking about an iPad? Can we please see some code samples? I can make mine full screen simply by resizing the UIView in my XIB file. How are you trying to do it?

UIWebView with links

I am creating a webview and loading content using "loadHTMLString" The content is loading I just can't get the links to work ex linking to google.com. Any help would be great.
UIWebView* newWeb = [[UIWebView alloc initWithFrame:CGRectMake(notificationPopUp.frame.origin.x+ 20,notificationPopUp.frame.origin.y-100,100, 100)];
//newWeb.backgroundColor = [UIColor clearColor];
newWeb.alpha = 0.7;
newWeb.opaque= NO;
newWeb.delegate= self;
NSString *html = [NSString stringWithFormat:#"<html><head><title></title><style type=\"text/css\">a{text-decoration:none}</style></head><body><FONT COLOR=\"#484848\"><p>Hello this is a Test</p></FONT></body></html>"];
[newWeb loadHTMLString:html baseURL:[NSURL URLWithString:#""]];
newWeb.userInteractionEnabled= TRUE;
[notificationPopUp addSubview:newWeb];
I added this code to an empty project and links are clickable. The only thing I can think of is your notificationPopUp view is somehow preventing taps from going to the webview.

Embedded Video in a UIView with iPhone

I would like to write an app that downloads (or streams) a video (encoded as required) in a view. I dont want to use the MPVideoPlayer from the SDK as it opens the video in full screen. I would like to place another UIView (transparent) over the video so that my users can annotate over the video.
Anyone have any idea or can point me to some code that will play video in a UIView?
If you want to do this you will need to include your own (software) video decoder, which will not have access to the hardware acceleration on the system. Even if you can get it working with acceptable performance it will be a huge battery drain.
If you wish to play a video in portrait mode, I have solution for that.
If you think that -MPMovie Player can run under a view, according to me it's not possible.
MP Movie player will work as Apple has designed.
So, MP Movie player will always / almost run in full screen.
Solution for portrait mode.
#interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
#end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
Hope that will help to you.
See, My question is very similar like yours.
playing video in custom size screen - view in iphone
Try this:
UIViewController *v = [[UIViewController alloc] init];
v.view.backgroundColor = [UIColor orangeColor];
NSString *path = [[NSBundle mainBundle] pathForResource:#"demo" ofType:#"mp4"];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(#"cannot find %# in bundle or doctuments", path);
}
NSURL *url = [NSURL fileURLWithPath:path];
MoviePlayerViewController *mpvc = [[MoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mpvc.moviePlayer];
mpvc.moviePlayer.fullscreen = NO;
[mpvc.moviePlayer setControlStyle:MPMovieControlStyleNone];
mpvc.moviePlayer.view.frame = CGRectMake(10, 100, 300, 300);
[v.view addSubview:mpvc.moviePlayer.view];
[mpvc.moviePlayer play];
[self presentModalViewController:v animated:YES];
[v release];
Maybe you should check the MediaPlayer's private headers, and simply add the video's view as your view's subview.