【问题标题】:UIWebView embedded video fullscreen issueUIWebView 嵌入式视频全屏问题
【发布时间】:2015-04-20 21:40:49
【问题描述】:

我正在使用 ifame api 将 youtube 视频嵌入到 UIWebView。关闭全屏模式时出现问题 - 播放器被转换到错误的位置。似乎隐藏动画有一些错误。我找到的唯一解决方案是将UIWebView 放在左上角。我用一个简单的项目创建了一个 github repo 来演示这个问题。 https://github.com/demonoid67/youtube-video-sample 。有人能帮我吗?感谢您的优势!

【问题讨论】:

    标签: ios iframe uiwebview youtube-api


    【解决方案1】:
                    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&controls=1' frameborder='0'>\
                                        </body>\
                                        </html>", youtubeWebView.frame.size.width, youtubeWebView.frame.size.height, selectedVideoModel.youtubeId];
    
                [youtubeWebView setAllowsInlineMediaPlayback:YES];
                [youtubeWebView setMediaPlaybackRequiresUserAction:NO];
                [youtubeWebView loadHTMLString:embedHTML baseURL: nil]; 
    

    也许这会对你有所帮助。

    【讨论】:

    • 谢谢,但是全屏的bug没有修复=(
    • 比你在这里要做的是添加一些约束。 :)
    • 尝试了这种方法,这甚至稍微修复了动画……不完全。但是非常感谢,这看起来好多了!
    猜你喜欢
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2014-04-04
    • 2012-10-28
    • 1970-01-01
    • 2016-08-09
    相关资源
    最近更新 更多