2011-06-07 79 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]; 
}