【发布时间】:2011-02-05 07:36:15
【问题描述】:
我想在我的 iPhone 模拟器中运行来自 youtube 的视频,视频的 URL 是这样的
http://www.youtube.com/v/zL0CCsdS1cE
但我无法将此视频加载到我的 iPhone 中,我正在使用 webview 来显示此视频,这是执行此操作的代码
objwebView = [[UIWebView alloc]initWithFrame:self.view.bounds];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:tempString]];
[objwebView loadRequest:request];
根据答案,我尝试了以下代码,这是我的代码的新版本
mywebView = [[UIWebView alloc]initWithFrame:self.view.bounds];
NSString *youTubeURL = @"http://www.youtube.com/v/zL0CCsdS1cE";
NSString *htmlString = [NSString stringWithFormat:@"<body style=\"margin:0;background-color:#222222;\"><div style=\"padding:%i;width:%i;height:%i;background-color:#ffffff;\"><video width=\"%i\" height=\"%i\" controls=\"\" autoplay=\"\" tabindex=\"0\"><source src=\"%@\"></source></video></div></body>",10, (int)(self.view.bounds.size.width), (int)(self.view.bounds.size.height), 320, 480,youTubeURL];
[mywebView loadHTMLString:htmlString baseURL:nil];
[self.view addSubview:mywebView];
但我仍然无法播放视频
请帮忙
【问题讨论】:
-
我只能看到一个白色的视图,仅此而已
-
您需要创建将播放视频的有效 html,即使用
标签: iphone objective-c xcode uiwebview