views:

147

answers:

2

Hi all,

I am using webkit to display youtube videos on iOS4. Upon click on the video it should automatically launch the player and display the video, but what's happening is video is rendered in the player but under the webview. What I want to do is make webview's alpha 0 so I'm using delegate

      webView:shouldStartLoadWithRequest:navigationType:

But this delegate is not getting called when tapped on the video to launch it. It's otherwise getting called while the first webview itself is launched from the url.

EDIT:

- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];   
NSURL *url = [NSURL URLWithString:urlAddress];           //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            //URL Requst Object
[web loadRequest:requestObj];              //Load the request

[self.view addSubview:web];
[web release];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicatorView.view removeFromSuperview];
web.alpha = 1.0;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {     
[self.view addSubview:activityIndicatorView.view];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
web.alpha = 0.0;
return YES;
}

Can anybody please help? It's really urgent.

Thanx in advance.

A: 

What I want to do is make webview's alpha 0 so I'm using delegate But this delegate is not getting called when tapped on the video to launch it. Why don't you set the web view alpha to 0 when you tap on the video?

Manjunath
The video that's displayed is inside webview, so what I am watching is webview so I need to use webview delegate methods. By "when tapped on the video to launch it", I mean is when I tap that particular link on webview which displays the first frame of my intended video [there're many on the same webview] which on tap is supposed to launch that video further.
neha
oh! can you just post some more code like how exactly you are launching the video[video URL].
Manjunath
Thanx for replying. I have edited my question to include the code I use.
neha
A: 
- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];   
NSURL *url = [NSURL URLWithString:urlAddress];           //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            //URL Requst Object
[web loadRequest:requestObj];              //Load the request

[self.view addSubview:web];
[web release];

}

here:

[self.view addSubview:web];

self.view is nil and adding view to nil will notretain your webview.

[web release];

You are releasing webview which is having retain count 0.

try

self.view = web;
[web release];

this will work for you.

Manjunath