在我的应用程序中,我需要在UIWebView
中播放单个视频,我可以在UIWebView
播放播放列表。
获取视频的链接是:
http://www.youtube.com/watch?v=5cCjaqi31XE&feature=youtube_gdata
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *videoURL=[self getYTUrlStr:stringURL];
NSURL *url=[NSURL URLWithString:videoURL];
[self.web loadRequest:[NSURLRequest requestWithURL:url]];
NSString *videoURL=[self getYTUrlStr:stringURL];
- (NSString*)getYTUrlStr:(NSString*)url
{
if (url == nil)
return nil;
NSString *retVal = [url stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"v/"];
NSRange pos=[retVal rangeOfString:@"version"];
if(pos.location == NSNotFound)
{
retVal = [retVal stringByAppendingString:@"?version=3&hl=en_EN"];
}
return retVal;
}
答案 0 :(得分:0)
需要修改链接,如下所示
videoURL = [videoURL stringByReplacingOccurrencesOfString:@"http://www.youtube.com/v/" withString:@"http://www.youtube.com/embed/"];
videoURL=[videoURL stringByReplacingOccurrencesOfString:@"?version=3&hl=en_EN" withString:@"?feature=player_detailpag"];
videoURL = [videoURL stringByReplacingOccurrencesOfString:@"?version=3&f=user_uploads&app=youtube_gdata" withString:@"?feature=player_detailpage"];
然后将实例方法提供给UIWebView实例方法loadRequest as NSURLRequest。