Youtube video autoplay on iPhone#39;s Safari or UIWebView(Youtube 视频在 iPhone 的 Safari 或 UIWebView 上自动播放)
问题描述
是否可以让 youtube 视频在 Safari 和/或 UIWebView 上自动播放?我在 iPhone 应用程序中看到过这种情况,tableview 显示没有 Youtube 预览图标的单元格(虽然很确定它是 UIWebView),当您点击单元格时它直接转到视频.
Is it possible to get a youtube video to autoplay on Safari and/or UIWebView? I've seen this done in an iPhone app, the tableview displays cells that do not have Youtube preview icon (pretty sure it's a UIWebView Though), when you tap the cell it directly goes to video.
这可以通过假装点击 youtube 视频来完成吗?如果是这样,怎么做?getElementById().click 会起作用吗?
Could this be done by faking a tap on the youtube video? If so, how? Would getElementById().click work?
推荐答案
诀窍是在 webview 中找到按钮.使用以下代码段.
the trick is to find the button in the webview. Use the following snippet.
- (void)loadWebUIViewWithYoutubeLink {
webView.delegate = self;
NSString *htmlString = [NSString stringWithFormat:[NSString
stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"YouTubeTemplate" ofType:@"txt"]],
@"b85hn8rJvgw", @"b85hn8rJvgw", nil];
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://youtube.com"]];
}
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if (view.subviews && [view.subviews count] > 0) {
for (UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if (button) return button;
}
}
return button;
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
UIButton *b = [self findButtonInView:_webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}
这篇关于Youtube 视频在 iPhone 的 Safari 或 UIWebView 上自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Youtube 视频在 iPhone 的 Safari 或 UIWebView 上自动播放


- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- UITextView 内容插图 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01