2
我在XCode6.1開發的iPad如何停止編程嵌入的UIWebView的Xcode內YouTube視頻
有我有一個嵌入式的視頻這一個UIWebView的應用程序的代碼是:
[self.webView setAllowsInlineMediaPlayback:YES];
[self.webView setMediaPlaybackRequiresUserAction:NO];
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='%f' height='%f' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'>\
</body>\
</html>", self.webView.frame.size.width, self.webView.frame.size.height, @"JW5meKfy3fY"];
[self.webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];
但如果我切換到另一個ViewController,播放器仍然在播放視頻,我希望它停止,該怎麼做?