2011-01-18 243 views
2

我的應用程序中有一個腳本在UIView的一部分中加載Youtube鏈接,該鏈接由我的服務器(mySQL /使用php)提供,並從中載入。 ..這個腳本下面工作正常.....但是...Youtube-iPhone-顯示視頻UIWebView

這是我現在有什麼,我正在尋找刪除程序化的部分(它給出的尺寸,並可能取代它與UIWebView)所以我可以即興使用IB,這將有助於我的應用程序啓動時,發生快速動畫,然後我希望這個youtube鏈接加載並在viewDidLoad完成後顯示。

.h文件中:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame; 

.m文件

//view did load function... 

[self embedYouTube:youtubestring frame:CGRectMake(69,72,184,138)]; 

//after the view did load is closed I have.. 

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame { 
NSString *embedHTML = @"\ 
<html><head>\ 
<style type=\"text/css\">\ 
body {\ 
background-color: transparent;\ 
color: white;\ 
}\ 
</style>\ 
</head><body style=\"margin:0\">\ 
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
</body></html>"; 
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height]; 
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame]; 
[videoView loadHTMLString:html baseURL:nil]; 
[self.view addSubview:videoView]; 
[videoView release]; 
} 

任何幫助將大大感激!謝謝

回答

1

艾姆,iPhone沒有Flash。它從來沒有,也許永遠不會有。在iPhone上打開YouTube視頻的唯一方法是通過YouTube應用,以其他格式播放。對於這樣的一個例子是 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com /v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"]];
您可以在這裏找到更多的細節:http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

+0

其實我的代碼現在工作開不起來了youtube的應用程序,實際上播放youtube視頻(從應用程序內),只是說,它在應用程序商店...它只是使用CGRect,而不是界面生成器....我明白iPhone不支持Flash,然而,他們認爲他們可能是一種解決方法...謝謝,雖然... – chance 2011-01-18 23:14:19

+0

這個鏈接告訴你如何嵌入你管視頻:http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-移動apps.html – 2012-05-14 04:53:58

7

這個工程使用IB創建UIWebViews中:

.h文件:

@property (nonatomic, retain) IBOutlet UIWebView *infoVideo1; 

-(void)embedYouTubeInWebView:(NSString*)url theWebView: (UIWebView *)aWebView; 

.m文件:

in viewDidLoad:

[self embedYouTubeInWebView:youTubeString theWebView:infoVideo1]; 

方法:

- (void)embedYouTubeInWebView:(NSString*)url theWebView:(UIWebView *)aWebView {  

NSString *embedHTML = @"\ 
<html><head>\ 
<style type=\"text/css\">\ 
body {\ 
background-color: transparent;\ 
color: white;\ 
}\ 
</style>\ 
</head><body style=\"margin:0\">\ 
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
</body></html>"; 

NSString* html = [NSString stringWithFormat:embedHTML, url, aWebView.frame.size.width, aWebView.frame.size.height]; 

[aWebView loadHTMLString:html baseURL:nil]; 
} 

你甚至可以有一個單一的屏幕上的多個網頁視圖。希望這可以幫助。