将带有字幕的youtube视频嵌入到iphone应用程序中

时间:2013-11-18 06:25:20

标签: ios iphone youtube

我正在尝试将YouTube视频嵌入到iphone应用中,并使用UIWebView并将来自youtube的嵌入代码作为html字符串加载。但我想控制字幕显示/改变与否。

这是我的代码

you2WebView = [[UIWebView alloc]initWithFrame:CGRectMake(10,70, 300, 300)];
you2WebView.allowsInlineMediaPlayback = YES;
you2WebView.mediaPlaybackRequiresUserAction = NO;
[self.view addSubview:you2WebView];

NSString* embedHTML = [NSString stringWithFormat:@"\
                       <html>\
                       <body style='margin:0px;padding:0px;'>\
                       <script type='text/javascript' src='http://www.youtube.com/iframe_api'>\
                       </script>\
                       <script type='text/javascript'>\
                       function onYouTubeIframeAPIReady()\
                       {\
                       ytplayer=new YT.Player('playerId',{\
                       events:{\
                       'onReady':onPlayerReady,\
                       }\
                       })\
                       }\
                       function onPlayerReady(a)\
                       {\
                       a.target.playVideo();\
                       }\
                       </script>\
                            <iframe id='playerId' type='text/html' width='%d' height='%d' src='http://www.youtube.com/embed/%@?rel=1&playsinline=1' frameborder='0'>\
                       </body>\
                       </html>", 300, 200, @"MOqfyGNNKvo"];
[you2WebView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];

这是我的按钮操作代码

-(void)clickedProgramBtn01{
[you2WebView stringByEvaluatingJavaScriptFromString:@"ytplayer.getOptions('cc')"];
NSLog(@"clicked!");
}

但它没有显示视频的副标题:'(

我想在点击ProgramBtn01

时在youtube视频上显示副标题

我该怎么办?

0 个答案:

没有答案