播放YouTube上使用 失败的iPhone,但iOS 6的下仍然工作为iPad(都工作得不错

2019-08-01 01:29发布

我用下面的HTML模板与手到一个UIWebView。 据我所知,这是播放YouTube视频的支持方式。

<html>
<body>
    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
    <div id="player"></div>

    <script>
        // 2. This code loads the IFrame Player API code asynchronously.
        var tag = document.createElement('script');
        tag.src = "http://www.youtube.com/player_api";
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

        // 3. This function creates an <iframe> (and YouTube player)
        //    after the API code downloads.
        var player;
        function onYouTubePlayerAPIReady() {
            player = new YT.Player('player', {
                                   playerVars: {'autoplay' : 1},
                                   height: 'VIDEO_HEIGHT',
                                   width: 'VIDEO_WIDTH',
                                   videoId: 'VIDEO_ID',
                                   events: {
                                   'onReady': onPlayerReady,
                                   'onStateChange': onPlayerStateChange
                                   }
                                   });
        }

        // 4. The API will call this function when the video player is ready.
        function onPlayerReady(event) {
            event.target.playVideo();
        }

        // 5. The API calls this function when the player's state changes.
        //    The function indicates that when playing a video (state=1),
        //    the player should play for six seconds and then stop.
        var done = false;
        function onPlayerStateChange(event) {
            if (event.data == YT.PlayerState.PLAYING && !done) {
                setTimeout(stopVideo, 6000);
                done = true;
            }
            if (event.data == YT.PlayerState.ENDED) {
                event.target.clearVideo();
                done = true;
            }
        }
        function stopVideo() {
            player.stopVideo();
        }
        </script>
</body>
</html>

很显然,我在替换为高度,宽度和VIDEOID PARAMS动态值。 这一直iOS 5的下iPhone和iPad上正常工作。 现在iOS 6中,当用户点击该视频出现下载和尝试启动三角形下,然后放弃。 以下是出现在日志文件中:

> 2012-09-30 23:27:48.759 xxxxx[6219:c07] [MPAVController] Autoplay: Enabling autoplay
> 2012-09-30 23:27:48.759 xxxxx[6219:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
> 2012-09-30 23:27:48.761 xxxxx[6219:c07] setting movie path: http://o-o---preferred---sn-ab5e6nll---v24---lscache1.c.youtube.com/videoplayback?upn=ag6FiVPe_XY&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=907064%2C908457%2C908310%2C914072%2C922401%2C920704%2C912806%2C913419%2C913546%2C913556%2C919349%2C919351%2C925109%2C919003%2C912706&key=yt1&expire=1349086864&itag=18&ipbits=8&sver=3&ratebypass=yes&mt=1349062032&ip=96.232.106.90&mv=m&source=youtube&ms=au&cp=U0hTTlBTVF9LTkNOM19ITVhJOnRob1gwVHFmQWUw&id=04d71fcbfe79a176&signature=33A43FD457B9FC5DD70284826E7D9BF113F9C0BB.9BC87BDCF97DFCB64F967D2CAD1051D2FC80DAC0

在模拟器相同的结果(所有支持的型号)和硬件设备(iPhone 4S)。 奇怪的是,它仍然适用于iPad 2的(仿真和硬件)就好了,这里是记录:

> 2012-09-30 23:32:01.586 xxxxx[6390:c07] [MPAVController] Autoplay: Enabling autoplay
> 2012-09-30 23:32:01.586 xxxxx[6390:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
> 2012-09-30 23:32:01.588 xxxxx[6390:c07] setting movie path: http://o-o---preferred---sn-ab5e6nll---v24---lscache1.c.youtube.com/videoplayback?upn=x7-Ydawtba4&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C926600%2C915704%2C914071%2C922401%2C920704%2C912806%2C913419%2C913546%2C913556%2C919349%2C919351%2C925109%2C919003%2C912706&key=yt1&expire=1349086864&itag=18&ipbits=8&sver=3&ratebypass=yes&mt=1349062271&ip=96.232.106.90&mv=m&source=youtube&ms=au&cp=U0hTTlBTVF9LTkNOM19ITVhJOmVQbjRzVUhBbFpF&id=04d71fcbfe79a176&signature=CD05405B78D1CD7987FE5B9F41DD2C15943BBC2E.863966BDB04003866C6740046C0C2499A0CC4DDD

我已经看到了一些类似的问题最近在这里,但至今没有人提出什么可能发生。 任何人都可以提出可能什么呢?

问候,-MpK-

Answer 1:

你的HTML工作对我很好(有高度,宽度和VIDEOID置换)原来的样子,装在iOS 6的一个UIWebView,在这两个模拟器和设备(iPhone 5)。

难道这个问题一直间歇YouTube或网络的问题? 有你再试一试,因为还是尝试了不同的视频ID?

干杯,克里斯



Answer 2:

我得到了同样的问题。 对我来说,这是怎么回事,因为我在viewWillAppear中加载的视频。 viewWillAppear中叫你管的视频加载后再次。 我固定它通过改变我的代码(viewWillAppear中称为只在iOS 6中后,视频加载)



文章来源: Playing youtube using