ios7 UIWebView Youtube Video

前端 未结 5 581
滥情空心
滥情空心 2021-02-04 10:33

I have a UIWebView subclass that I used to play both youtube and local videos. Worked perfectly under iOS6. In upgrading to iOS7 I\'ve encountered a problem I don\'t really kn

5条回答
  •  时光说笑
    2021-02-04 10:56

    Using this you can run youtube video in your view..

    UIWebView *videoView = [[UIWebView alloc] initWithFrame:self.view.bounds];

        NSString *strparse = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@",youtubeVideoId];
        NSRange rng = [strparse rangeOfString: @"watch?v="];
        strparse = [strparse substringFromIndex:rng.location];
        rng = [strparse rangeOfString:@"&feature="];
    
    
        if (rng.length >0)
        {
            strparse = [strparse substringToIndex:rng.location];
        }
        strparse = [strparse stringByReplacingOccurrencesOfString:@"watch?v=" withString:@""];
        //http://www.youtube.com/embed/FJkiwbqlSy0
        NSString *youTubeVideoHTML =[NSString stringWithFormat:@"  
    ",0.0, 0.0,youtubeVideoId]; videoView.scalesPageToFit=NO; videoView.mediaPlaybackRequiresUserAction=NO; videoView.backgroundColor = [UIColor clearColor]; videoView.opaque= NO; [SharedObj showLoadingWithText:@""]; [videoView loadHTMLString:youTubeVideoHTML baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@",youtubeVideoId]]]; [self.view addSubview:videoView];

提交回复
热议问题