gpt4 book ai didi

iphone - 使用UIWebview播放嵌入式YouTube视频

转载 作者:行者123 更新时间:2023-12-03 06:02:44 25 4
gpt4 key购买 nike

将Youtube视频嵌入UIWebview中。当按下UIButton时,如何使用UIWebview播放此视频。

- (void)viewDidLoad
{
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

NSString *videoUrl = @"http://http://www.youtube.com/v/oHg5SJYRHA0";
NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"320\" height=\"480\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"480\"></embed></object></div></body></html>",videoUrl,videoUrl] ;

[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];

//[window addSubview:webView];
[webView release];

[super viewDidLoad];
// Do any additional setup after loading the view.
}

当用户按下此UIButton时,它应开始播放嵌入式youtube视频
UIButton *videoButton = [UIButton buttonWithType:UIButtonTypeCustom];
[videoButton addTarget:self action:@selector(VideoAction:) forControlEvents:UIControlEventTouchUpInside];
videoButton.frame = CGRectMake(0, 0, 40, 40);
UIImage *icn = [UIImage imageNamed:@"Video_icon.png"];
[videoButton setImage:icn forState:UIControlStateNormal];
UIBarButtonItem *video = [[UIBarButtonItem alloc] initWithCustomView:videoButton];

我如何播放YouTube视频。

感谢帮助。

最佳答案

你为什么不试试这个:

            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=oHg5SJYRHA0"]]]
[self.view addSubview:webView];

关于iphone - 使用UIWebview播放嵌入式YouTube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11922579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com