开发者

How to start an embedded YouTube video at a certain timestamp in iphone

I want to start an embedded youtube video from a timestamp. I know how to do it on browsers but that does not seem to work on iPhone. Here is a detailed tutorial by MATT CUTTS.

Start an embedded video at a certain timestamp

In above link you can see if we append #t=31m08s or &start=200 in url it works but when i use same url inside UiWebView, default youtube player starts video from first frame. Can anyone have an idea or have implemented same. I am using UIWebView with embed tag to play youtube video. I am using below embed tag inside UIWebView.

 <embed id="yt" src="http://www.youtube.com/watch?v=dsFQ9kM1qDs" type="applicatio开发者_如何学编程n/x-shockwave-flash" width= "500" height="400"></embed>

Below is the code i am using to play this video in UIWebView

- (IBAction) playYoutube {
    [self embedYouTube:@"http://www.youtube.com/watch?v=dsFQ9kM1qDs#t=2m08s"];
}

- (void)embedYouTube:(NSString*)url
{  
    [webView setFrame:CGRectMake(0, 0, 480, 320)];
    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, webView.frame.size.width,  webView.frame.size.height]; 
    [webView loadHTMLString:html baseURL:nil];  
}  


According to the Youtube API team there no way to do this with iPhone/iPad etc. - see https://groups.google.com/group/youtube-api-gdata/browse_thread/thread/ef4f434347622448/0f65f465d671d74c


Try adding ?t=1m10s at the end of the link

E.g. src="https://youtu.be/dsFQ9kM1qDs?t=1m10s"

Note: Make sure that you use youtu.be link (the link that you get when you click share button on YouTube) and not youtube.com link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜