2011-06-07 122 views
0

我已经成功实现了嵌入式vimeo视频到我的应用程序,但是我想创建占位符图像作为覆盖视频,而他们不玩。有没有人有如何做到这一点的想法?如何将占位符图像添加到我的嵌入Vimeo和Youtube视频?

#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]; 
    //[mainView addSubview:aWebView]; 
    //[self.mainView addSubview:videoView]; 
    [aWebView release]; 


} 

- (void)dealloc { 
    [toolbar release]; 
    [super dealloc]; 
} 
@end 

这是我到目前为止。

回答

0

我们对YouTube视频采取的方法如下(我想你可以做一些类似的VIMEO)。

你需要做的是在webview上面设置一个imageview,它应该显示你的vimeo视频的缩略图img(这是我从你的问题中了解到的)。

可以检索与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. 

你会得到三个缩略图,一个用于不同尺寸(小,中,大)。

由于您的imageView将隐藏web视图和其上的按钮以开始播放,因此您需要在点击uimageview(或只是在顶部设置一个uibutton)时执行操作。然后,选择器应该这样调用:

** 
* 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]; 
} 
相关问题