【问题标题】:Embedding YTPlayerView In UIScrollView在 UIScrollView 中嵌入 YTPlayerView
【发布时间】:2015-10-14 05:50:10
【问题描述】:

我正在创建一个 UIScrollView,它可以保存来自不同来源的图像和视频。我首先为每个图像/视频创建并添加了一个 UIView 到 UIScrollView,然后添加图像/视频视图/层。这适用于使用 AVFoundation 的图像和视频;但是,不适用于使用 Youtube API 的视频。

这是我在 UIScrollView 中将 YTPlayerView 添加到 UIView 的代码:

YTPlayerView * youtubePlayerView = [[YTPlayerView alloc] initWithFrame: CGRectMake(0, 0, self.scrollViewWidth, self.scrollViewHeight)];
youtubePlayerView.bounds = CGRectMake(0, 0, self.scrollViewWidth, self.scrollViewHeight);

NSString * youtubePath = [media getMediaPath]; //Valid Youtube URL as NSString

NSMutableString *videoUrlCopy = [NSMutableString stringWithString:youtubePath];

NSString *vID =  [videoUrlCopy lastPathComponent];

NSDictionary *playerVars = @{
                            @"playsinline" : @1
                            };

youtubePlayerView.delegate = self;

[contentView addSubview:youtubePlayerView]; //ContentView is subview of UIScrollview

[youtubePlayerView loadWithVideoId:vID playerVars:playerVars];
[youtubePlayerView playVideo];

当我尝试使用 loadWithVideoId 加载 youtube 视频时,该过程在此处的 YTPlayerView 内终止:UIWebView *webView = [[UIWebView alloc] initWithFrame:self.bounds]; throwing EXC_BAD_ACCESS

- (UIWebView *)createNewWebView {
  UIWebView *webView = [[UIWebView alloc] initWithFrame:self.bounds];
  webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  webView.scrollView.scrollEnabled = NO;
  webView.scrollView.bounces = NO;
  return webView;
}

有趣的是,我已经获得了 Youtube 视频,显示将 YTPlayerView 作为子视图直接添加到 self.view。有什么建议吗?

【问题讨论】:

    标签: ios objective-c uiscrollview uiwebview youtube-api


    【解决方案1】:

    我想通了,使用

    pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'
    

    而不是使用pod 'youtube-ios-player-helper'

    干杯

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 2010-12-23
      • 2016-03-18
      • 2015-11-09
      • 1970-01-01
      相关资源
      最近更新 更多