在IOS中的UIWebView中播放youtube视频时,设备无法获得声音的问题

Ata*_*dal 0 youtube video objective-c uiwebview

我用的UIWebView是玩Yoytube Video.
我的代码就是这样

self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,320, 240)];
[self.webView setBackgroundColor:[UIColor clearColor]];
[self.webView setOpaque:NO];
self.webView.delegate=self;
[self.webView setAllowsInlineMediaPlayback:YES];
[self.webView setMediaPlaybackRequiresUserAction:NO];
[self.viewContent addSubview:self.webView];

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/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'>\
                                   </body>\
                                   </html>", 320, 240, [dictIW valueForKey:@"embedCode"]];
[self.webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];
Run Code Online (Sandbox Code Playgroud)

在模拟器中它玩起来非常好.但是当我在iPhone或iPad上播放这个视频时,视频正在显示,但声音没有得到.
请帮忙.

sop*_*rof 6

在创建UIWebView之前,将音频会话类别设置为"回放"

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL flag;
NSError *setCategoryError = nil;
flag = [audioSession setCategory:AVAudioSessionCategoryPlayback
                     error:&setCategoryError];
Run Code Online (Sandbox Code Playgroud)