Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

sdk - Youtube - iPhone - displaying UIWebView of video

I have a script in my app that loads a Youtube link in a section of the UIView, the link is provided by my server (mySQL/using php) and from that it is loaded... this script below works fine..... however...

Here is what I have right now, I was looking to remove the programmatically part (where it gives the dimensions and possibly replace it with a UIWebView) to it, so I could improvise using IB, this will help when my application launches, a quick animation occurs and then I want this youtube link to load and display after viewDidLoad is completed.

.h file:

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

.m file

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

any help would greatly be appreciated!! thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...