Embed youtube video in iOS App

后端 未结 2 1247
陌清茗
陌清茗 2021-01-03 02:42

I want to embed a youtube video into a webviewer whenever I press a button. I have this code

- (IBAction)testBtn:(id)sender {

    NSString *code = @\"

        
2条回答
  •  礼貌的吻别
    2021-01-03 03:03

    Try this one this is working perfect. You use youtube Url as "http://www.youtube.com/v/YOU_TUBE_VIDEO_ID".

     UIWebView * youTubeWebView=[[UIWebView alloc]initWithFrame:CGRectMake(0,0,320,320)];
        youTubeWebView.allowsInlineMediaPlayback=YES;
        youTubeWebView.mediaPlaybackRequiresUserAction=NO;
        youTubeWebView.mediaPlaybackAllowsAirPlay=YES;
        youTubeWebView.delegate=self;
        youTubeWebView.scrollView.bounces=NO;
    
        NSString *linkObj=@"http://www.youtube.com/v/1iBIcJFRLBA";//@"http://www.youtube.com/v/6MaSTM769Gk";
        NSLog(@"linkObj1_________________%@",linkObj);
        NSString *embedHTML = @"\
        \
        \\\\\\";
    
        NSString *html = [NSString stringWithFormat:embedHTML, linkObj];
        [youTubeWebView loadHTMLString:html baseURL:nil];
        [self.view addSubview:youTubeWebView];
    

提交回复
热议问题