2010-09-23 87 views
4

我正在使用webkit在iOS4上顯示youtube視頻。點擊視頻後,它應該自動啓動播放器並顯示視頻,但發生的情況是視頻在播放器中呈現,但在web視圖下呈現。我想要做的就是讓的WebView阿爾法0所以我使用代理webView:shouldStartLoadWithRequest:navigationType:未在webkit上使用youtube視頻鏈接調用iphone

 webView:shouldStartLoadWithRequest:navigationType: 

但在視頻拍了拍啓動它時,該委託不獲取調用。這是否被調用,而第一個WebView本身是從URL啓動。

編輯:

- (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; 
} 

任何人可以請幫助?這真的很緊急。

Thanx提前。

+0

您是否找到任何答案?我面臨同樣的問題。 – 2011-10-19 08:42:34

+0

當我在玩耍時,我發現了一些錯誤,並給出了以下日誌。從日誌中可以明顯看出,webview在內部使用AVFoundation和Movie Player,或許我們可以以某種方式使用該信息? - 2011-10-19 15:19:22.567 PlayYoutube [2720:707] _serverConnectionDiedNotification。 Info - notification = Error Domain = AVFoundationErrorDomain Code = -11819「Can not Complete Action」UserInfo = 0x19cf20 {NSLocalizedRecoverySuggestion =稍後再試,NSLocalizedDescription =無法完成操作},AVPlayer = ,currentTime = 0.00 – 2011-10-19 09:51:03

+0

也許這個幫助:https://groups.google.com/group/phonegap/browse_thread/thread/3dfbd35e8db5729f/6d30915b2dbc1277,https://devforums.apple.com/message/26261#26261。我認爲問題在於,當視頻使用JavaScript加載時,代理不會被調用。您可能需要擴展JavaScript代碼,但這並非總是可行,特別是在使用外部網站時。 – 2011-11-18 17:29:32

回答

1
- (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]; 

} 

這裏:

[self.view addSubview:網頁];

self.view爲零,將視圖添加到零將不會保留您的webview。

[web release];

您正在釋放其爲具有保留計數的WebView 0

嘗試

self.view = web; 
[web release]; 

這會爲你工作。

相關問題