OGeek|极客世界-中国程序员成长平台

标题: ios - 在 UITableview Cell 中播放视频 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:44
标题: ios - 在 UITableview Cell 中播放视频

在我的一个应用程序中,我必须在 UITableviewcell 中播放视频,一次在一个单元格中播放一个视频,并且当滚动 UITableview 和单元格隐藏视频时应该停止。我的项目在 Objc 中。

对任何第三方有什么建议吗?

提前致谢



Best Answer-推荐答案


在该单元格中使用 UIWebView,它会正常工作

 NSString *baseUrl = @"http://www.youtube.com/embed/";
    NSString *videoUrl = [NSString stringWithFormat"%@%@",baseUrl,embedCode];
    videoUrl = [videoUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    NSString *embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </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,videoUrl, 300.0, 200.0];
    UIWebView *videoWebView = [[UIWebView alloc] initWithFrame:CGRectMake(8, 10.0, width-16, (width-16)/1.8)];
    [videoWebView setAllowsInlineMediaPlayback:YES];
    videoWebView.mediaPlaybackRequiresUserAction = YES;
    videoWebView.scrollView.scrollEnabled = NO;
    videoWebView.scrollView.bounces = NO;
    [videoWebView loadHTMLString:html baseURL:nil];
    [self.contentView addSubview:videoWebView];

关于ios - 在 UITableview Cell 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44172987/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4