How to embed YouTube video on iOS and play it directly on UIWebView without full screen?

前端 未结 2 1501
攒了一身酷
攒了一身酷 2020-11-29 00:55

I am using this code to play YouTube videos on iOS

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame
{
    NSString *htmlString = [NSString stri         


        
2条回答
  •  时光取名叫无心
    2020-11-29 01:42

    If anyone is still facing this problem, below is by far the best solution I have seen. Works like a charm.

    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10,300, 200)];
            [self.webView setAllowsInlineMediaPlayback:YES];
            [self.webView setMediaPlaybackRequiresUserAction:NO];
    
            [self.view addSubview:self.webView];
    
            NSString* embedHTML = [NSString stringWithFormat:@"\
                                   \
                                        \
                                            \
                                            \