How can i add placeholder images to my embedded Vimeo and Youtube videos?
I have successfully implemented embedded vimeo videos into my app, however i would like to create placeholder images as an overlay on the videos whilst they are not playing. Does anyone have an idea of how to do this?
#import "FifthDetailViewController.h"
@interface FifthDetailViewController (Private)
- (void)embedVimeoInWebView:(NSString *)urlString webView: (UIWebView *)aWebView;
@end
@implementation FifthDetailViewController
@synthesize toolbar;
@synthesize videoOne;
#pragma mark -
#pragma mark View lifecycle
- (void) viewDidLoad{
[super viewDidLoad];
[self embedVimeoInWebView:@"http://player.vimeo.com/video/19967404" webView:videoOne];
}
- (void)embedVimeoInWebView:(NSString *)urlString webView:(UIWebView *)aWebView {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:-2\">\
<iframe src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></iframe>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, aWebView.frame.size.width, aWebView.frame.size.height];
//UIWebView *aWebView = [[UIWebView alloc] initWithFrame:frame];
[aWebView loadHTMLString:html baseURL:nil];
//----Disable Scroll UIWebView----
[[[aWebView subviews] lastObject] setScrollEnabled:NO];
//[mainV开发者_JAVA技巧iew addSubview:aWebView];
//[self.mainView addSubview:videoView];
[aWebView release];
}
- (void)dealloc {
[toolbar release];
[super dealloc];
}
@end
This is what i have so far.
The approach we took with youtube videos is as follow (I guess you can do something similar with vimeo).
What you need to do is set an imageview on top the webview, which should display the thumbnail img of your vimeo video (this is what I understand from your question).
You can retrieve thumbnail images with Vimeo API
To get data about a specific video, use the following url:
http://vimeo.com/api/v2/video/video_id.output
video_id The ID of the video you want information for.
output Specify the output type. We currently offer JSON, PHP, and XML formats.
You'll get three thumbnails, one for different size (small, medium, large).
Since your imageView will hide the webview and the button on it to start playing, you will need to perform an action when you tap the uimageview (or just set an uibutton on top). Then, the selector should call something like this:
**
* When webview has loaded, send an action to itself so it starts the video
* playback automatically
*/
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
_webView.hidden = NO;
UIButton *b = [self findButtonInView:_webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}
- (IBAction) playVideo:(id)sender {
NSString *key = [NSString stringWithFormat:@"%d", [sender tag]];
UIWebView *youtubeView =
[[UIWebView alloc] initWithFrame:CGRectMake(-180, 100, 160, 80)];
youtubeView.tag = 3000;
youtubeView.hidden = YES;
[self.tableView addSubview:youtubeView];
[self embedYouTubeIntoWebview:youtubeView withURL:[[self.nodeCollection objectForKey:
key] valueForKey:@"videoURL"]
inFrame:youtubeView.frame];
[youtubeView release];
}
精彩评论