Reputation: 310
I am not able to play video in this format.
http://www.youtube.com/embed/lNOMZoF9VlM?rel=0
my html string.
NSString *html = [NSString stringWithFormat:@"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=%@ type=\"application/x-shockwave-flash\" \
width=\"120\" height=\"120\"></embed>\
</body></html>",str];
please reply.
Upvotes: 2
Views: 788
Reputation:
Try this it work for me...
CGRect frame = CGRectMake(40, 55, width, height);
NSString *embedHTML =[NSString stringWithFormat:@"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: blue;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe height=\"220\" width=\"400\" src=\"http://www.youtube.com/embed/lNOMZoF9VlM\"></iframe>\
</body></html>"];
webview = [[UIWebView alloc] initWithFrame:frame];
webview.backgroundColor = [UIColor clearColor];
webview.scrollView.scrollEnabled =NO;
[webview loadHTMLString:embedHTML baseURL:nil];
[self.view addSubview:webview];
Upvotes: 2
Reputation: 10775
I implemented a Youtube View like below. Important thing is that this can only be used with an url string for youtube's embed-url which should look like this:
<iframe width="420" height="315" src="http://www.youtube.com/embed/ntQDyLpoLWM" frameborder="0" allowfullscreen></iframe>
(Could it be a problem that all code above has a type="application/x-shockwave-flash"
in it?)
Here's my code:
#import "YoutubeView.h"
@implementation YoutubeView
- (id)initWithFrame:(CGRect)frame andURL:(NSString *)url
{
self = [super initWithFrame:frame];
if (self)
{
urlString = [url retain];
webView = [[UIWebView alloc] initWithFrame:self.bounds];
[webView.scrollView setBounces:NO];
[self addSubview:webView];
}
return self;
}
-(void)layoutSubviews
{
webView.frame = self.bounds;
NSMutableString *html = [[NSMutableString alloc] init];
[html appendString:@"<html>"];
[html appendString:@"<head>"];
[html appendString:@"<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\">"];
[html appendString:@"</head>"];
[html appendString:@"<body style=\"border:0; margin:0; padding:0;\">"];
[html appendFormat:@"<iframe width=\"%d\" height=\"%d\" src=\"%@\" frameborder=\"0\" allowfullscreen>", (int) roundf(self.bounds.size.width), (int) roundf(self.bounds.size.height), urlString];
[html appendString:@"</iframe>"];
[html appendString:@"</body>"];
[html appendString:@"</html>"];
[webView loadHTMLString:html baseURL:nil];
[html release];
}
-(void)dealloc
{
[webView release];
[urlString release];
[super dealloc];
}
@end
Upvotes: 0
Reputation: 4461
You can't play youtube video directly to your iPhone in WebView. First you need to convert to the embedded HTML and then you can easily play youtube video.
UIWebView *webview=[[UIWebView alloc] initWithFrame:CGRectMake(vid.x_Pos, vid.y_Pos, vid.width,vid.height)];
webview.backgroundColor = [UIColor clearColor];
embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"http://www.youtube.com/embed/lNOMZoF9VlM?rel=0\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, vid.width, vid.height];
[webview loadHTMLString:html baseURL:nil];
[portraitView addSubview:webview];
[webview release];
Let me know if you have any more questions.
Upvotes: 0