Youtube - iPhone - displaying UIWebView of video

僤鯓⒐⒋嵵緔 提交于 2019-11-29 05:18:26

This works using UIWebViews created in IB:

The .h File:

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

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

The .m File:

in the viewDidLoad:

[self embedYouTubeInWebView:youTubeString theWebView:infoVideo1];

the Method:

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

You can even have multiple webViews on a single screen. Hope this helps.

Aehm, the iPhone doesn't have Flash. It never had and probably never will have. The only way to open youtube videos on the iPhone is via the youtube app, which plays them back in another format. An example for this is [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com /v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"]];
You can find more detail here: http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

iOS has a safari plugin which plays youtube videos if they embedded as flash.

This uiwebview category I've put together will embed videos for you without haven't to leave the application or a tutorial :-)

https://github.com/enigmaticflare/UIWebView-YouTube--iOS-Category--ARC-compliant-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!