我正在创建一个可以保存来自不同来源的图像和视频的UIScrollView。我首先创建了每个图像/视频的UIView并将其添加到UIScrollView中,然后添加图像/视频视图/层。这适用于使用AVFoundation的图像和视频;但是,不适用于使用Youtube API的视频。
下面是将YTPlayerView添加到UIScrollView中的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];抛出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中。有什么建议吗?
发布于 2016-02-26 01:17:51
我找出了答案,使用
pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'不使用pod 'youtube-ios-player-helper'
干杯
https://stackoverflow.com/questions/31595569
复制相似问题