6

如何在 a 中获取 YouTube 视频UITableViewCell,以及如何处理播放视频的-Done按钮UIWebView

我已将视频嵌入到视图中,但就像在图像上一样。我想要这张Done图片中的这个按钮:

截屏

我想在返回视图时打开另一个屏幕,而不是前一个视图。

-(void)viewDidLoad {
    [super viewDidLoad];
    videoURL = [[NSString alloc]init];
    videoURL =@"http://www.youtube.com/watch?v=aE2b75FFZPI";
    [self embedYouTube:videoURL frame:CGRectMake(10, 85, 300, 180)];
}


- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {  
    NSString* embedHTML = @"\ <html><head>\ <style type=\"text/css\">\ body {\ background-color: transparent;\ color: red;\ }\ </style>\ </head><body style=\"margin:0\">\ <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ width=\"%0.0f\" height=\"%0.0f\"></embed>\ </body></html>";  
    NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];  
    if (videoView == nil) {  
        videoView = [[UIWebView alloc] initWithFrame:frame];  
        [self.view addSubview:videoView];  
        NSLog(@"html%@",html);
    }  

    [videoView loadHTMLString:html baseURL:nil];  
}

我需要一些帮助。我进行了搜索,但没有得到任何东西。

4

2 回答 2

0

由于这一直没有得到答复,我想我可以提供一个建议。我相信最终结果与您正在寻找的结果相同,但到达那里的路径略有不同。

因此,据我了解,您希望 UITableView 控制器在您单击它们时显示播放的 YouTube 视频列表。这是我在我的一个应用程序中处理这种情况的方法。

  1. 您需要在列表中获取所需视频的 RSS 提要。这很简单……如果是针对用户的,格式为http://www.youtube.com/rss/user/{USERNAME}/videos.rss
  2. 因此,您需要从那里将 RSS 提要解析为具有标题、描述、缩略图和视频链接的对象列表。所有这些都在 RSS 中提供,我使用NSXMLParser来完成这项工作。
  3. 一旦你有一个很好的值对象列表可以使用,你需要做的就是让表触发MPMoviePlayerViewController并将 URL 传递给它来播放电影。

didSelectRowAtIndexPath 实现

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /** self.items is just a mutable array of video objects that is the underlying 
        datasource for the table.  The Video object is just a simple value object 
        I created myself */
    Video *video = [self.items objectAtIndex:[indexPath row]];

    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:video.video]];

    [self presentMoviePlayerViewControllerAnimated:mp];

    [mp release];
}

这是我的 Video 类的界面的样子

@interface Video : NSManagedObject {

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSString * comments;
@property (nonatomic, retain) NSString * thumbnail;
@property (nonatomic, retain) NSString * pubDate;
@property (nonatomic, retain) NSString * video;
@property (nonatomic, retain) NSString * guid;
@property (nonatomic, retain) NSString * desc;

@end

差不多就是这样,一个在 UITableViewController 中显示 YouTube 视频的好方法。我不会进入 XML 解析,那里有大量关于如何做到这一点的文档。我刚刚做了一个快速的谷歌搜索,这个博客实际上深入了解了我正在谈论的内容:

http://useyourloaf.com/blog/2010/10/16/parsing-an-rss-feed-using-nsxmlparser.html

希望这能让你继续前进。我知道这并没有解决将标记放在 WebView 中的问题,但我认为您会发现这种方式更直观,并且由于没有太多响应......希望它能让您启动并运行。

于 2012-06-22T17:31:37.823 回答
0

您要做的就是弄乱 UIWebView 使用的媒体播放器。这可以通过监视 uiviewanimation 通知然后通过一堆子视图来完成,但它会涉及使用私有方法,因此不建议特别推荐,因为私有媒体播放器的行为方式会随每个操作系统而变化。我建议使用 jerrylroberts 的答案并获得 YouTube 视频的直接链接。

于 2013-07-20T03:11:17.343 回答