XCDYouTubeVideoPlayer打开和关闭

时间:2014-01-24 08:33:47

标签: ios objective-c

我开始使用XCDYouTubeVideoPlayer。它似乎有一些小问题。当我使用该方法(如下所示)调用播放器时,它会打开它并立即关闭它。

我导入了以下框架: mediaplayer AVfoundation

并添加了`XCDYouTubeVideoPlayerViewController.h和.m

在viewController.m中我添加了这个方法:

- (IBAction) play:(id)sender
{
[self.view endEditing:YES];
    NSString *link = @"m01MYOpbdIk";

XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:link];

[self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];
}

此刻正好打开和关闭XCDYouTubeVideoPlayer。我做错了什么?

2 个答案:

答案 0 :(得分:1)

我不明白为什么,但对我来说,在iOS8中行

  XCDYouTubeVideoPlayerViewController.m at #79

正在调用方法:

 - (id) initWithContentURL:(NSURL *)contentURL
 {
      @throw [NSException exceptionWithName:NSGenericException reason:@"Use the   
        `   initWithVideoIdentifier:` method instead." userInfo:nil];
 }

我只是评论并且有效!

答案 1 :(得分:0)

XCDYouTubeVideoPlayer库通过附加提供签名的网址来构建youtube“流媒体链接”。看来“url”现在有了签名和“sig”键为null,从而否定了函数中的if语句

  

(NSURL *)videoURLWithData:(NSData *)数据错误:(NSError * __autoreleasing *)错误

转到文件

  

XCDYouTubeVideoPlayerViewController.m,#248

你会看到一个for循环

for (NSString *streamQuery in streamQueries)
{
   NSDictionary *stream = DictionaryWithQueryString(streamQuery, queryEncoding);
   NSString *type = stream[@"type"];
   NSString *urlString = stream[@"url"];
   NSString *signature = stream[@"sig"];
   if (urlString && signature && [AVURLAsset isPlayableExtendedMIMEType:type])
   {
     NSURL *streamURL = [NSURL URLWithString:[NSString        
                                   stringWithFormat:@"%@&signature=%@", 
                                   urlString, 
                                   signature]];
     streamURLs[@([stream[@"itag"] integerValue])] = streamURL;
   }

将其更改为此(从if语句中删除签名变量并修改URLWithString)

for (NSString *streamQuery in streamQueries)
{
   NSDictionary *stream = DictionaryWithQueryString(streamQuery, queryEncoding);
   NSString *type = stream[@"type"];
   NSString *urlString = stream[@"url"];
   if (urlString &&  [AVURLAsset isPlayableExtendedMIMEType:type])
   {
     NSURL *streamURL = [NSURL URLWithString:urlString];
     streamURLs[@([stream[@"itag"] integerValue])] = streamURL;
   }