iOS開發 播放Youtube影片

如果要在iPhone製作播放Youtube影片的功能

可以使用以下方式

利用UIWebView


UITextView *myUITextView1;

if(videoView == nil)
{
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 37, 320, 260)];
}

videoView.backgroundColor = [UIColor clearColor];

videoView.opaque = NO;

[self.view addSubview:videoView];

NSString *htmlString =@"<html><head>"

"<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>"

"<body style=\"background:#FFFFF;margin-top:20px;margin-left:0px\">"

"<div><object width=\"320\" height=\"240\">"

"<param name=\"wmode\" value=\"transparent\"></param>"

"<embed src=\"http://www.youtube.com/v/9-cDZnLhUIc?f=user_favorites&app=youtube_gdata\""

"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"240\"></embed>"

"</object></div></body></html>";

[videoView loadHTMLString:htmlString baseURL:nil];