1. 在原有的app中執行,不可離開
2. 全螢幕
3. 橫向看
我的方式是先加入一個ViewController ,命名為YouTuBeController,為了設成橫向,如下所示:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == (UIDeviceOrientationLandscapeLeft) );
}
再來是要加入YouTuBe影片,用WebView來載入,我拿足球影片來當範例(取得影片的url,請參考我最底下網址參考的最後一個link,有官方說明)程式碼如下:
UIWebView *youTubeWebView = nil;
if (youTubeWebView == nil) {
UIScreen *screen = [UIScreen mainScreen];
CGRect frame = [screen applicationFrame];
youTubeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, frame.size.height, frame.size.width)];
youTubeWebView.delegate = self;
}
NSString* embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe width=\"%0.0f\" height=\"%0.0f\" src=\"%@?rel=0\" frameborder=\"0\" allowfullscreen></iframe> \
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, youTubeWebView.frame.size.width, youTubeWebView.frame.size.height, @"http://www.youtube.com/embed/yGS6F-buYZw"];
[youTubeWebView loadHTMLString:html baseURL:nil];
self.view = youTubeWebView; //將view設成剛建好的webview
參考網址
How To Play YouTube Videos Within an Application
How to play youtube movie?
How to Watch YouTube Videos on Your iPhone
YouTube APIs + iPhone = Cool mobile apps
官網:
如何嵌入 YouTube 影片
沒有留言:
張貼留言