如果用户无需触摸UIWebView本身,如何启动YouTube视频? [英] How can I start a YouTube video without the user touching the UIWebView itself?

查看:91
本文介绍了如果用户无需触摸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,将请求URL设置为视频的flv路径? (任何api建议?)

  3. 最后一个是模拟WebView内部的触摸,因此它会启动视频,即使用户没有触及UIWebView。有可能吗?

  4. 还有其他任何建议吗?

  1. We've thought of enabling a WebView at didSelectRow, embed the HTML data and show it fullscreen, but with this way users would need to touch once again into the play button to play the video, am I right?
  2. Would it be possible to use MPMoviePlayerController instead, setting as the request URL the flv path of the video? (any api suggested?)
  3. The last one would be simulating the touch inside the WebView so it would start the video, even if the user hasn't touched the UIWebView. Is it possible?
  4. Any other suggestions?


推荐答案

<回答自己。我找到了解决方案。此代码将自动播放webview。

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天全站免登陆