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 上自动播放


基础教程推荐
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01