如何在用户不触摸 UIWebView 本身的情况下启动 YouTube 视频? [英] How can I start a YouTube video without the user touching the UIWebView itself?

查看:29
本文介绍了如何在用户不触摸 UIWebView 本身的情况下启动 YouTube 视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个应用程序,其中包含一个带有一些标准单元格的 TableView,以及一个 YouTube 视频列表.我们知道如何将 YouTube 视频数据嵌入 UIWebView 并在用户触摸它时播放.但是为了做到这一点,用户必须触摸 UIWebView.

We're developing an app which contains a TableView with some standard cells, but also a list of YouTube videos. We know how to embed the YouTube video data into a UIWebView and play it when the user touches it. But in order to do that, users must touch the UIWebView.

因为它是一个TableView,所以每个单元格都是典型的单元格,左边是缩略图,右边是一些信息和一个附件按钮.我们希望让用户触摸单元格中的任何位置,而不仅仅是 WebView (didSelectRow),以便视频开始.

Since it's a TableView, every cell is the typical cell with the thumbnail on the left, some info and an accessory button on the right. We want to let users touch anywhere in the cell, not just the WebView (didSelectRow) so the video would start.

我们如何才能做到这一点?

How can we achieve this?

  1. 我们曾想过在 didSelectRow 上启用 WebView,嵌入 HTML 数据并全屏显示,但通过这种方式,用户需要再次触摸播放按钮才能播放视频,对吗?
  2. 是否可以改用 MPMoviePlayerController,将视频的 flv 路径设置为请求 URL?(任何 api 建议?)
  3. 最后一个将模拟 WebView 内部的触摸,因此它会启动视频,即使用户没有触摸 UIWebView.可能吗?
  4. 还有其他建议吗?

推荐答案

回答我自己.我找到了解决方案.此代码将自动播放网络视图.

Answering myself. I've found the solution. This code will autoplay the webview.

 - (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];
}

在 iPhone 的 Safari 或 UIWebView 上自动播放 YouTube 视频

希望能帮到别人.

这篇关于如何在用户不触摸 UIWebView 本身的情况下启动 YouTube 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆