seekTo()不是YouTube iframe API错误的功能 [英] seekTo() is not a function YouTube iframe API error

查看:185
本文介绍了seekTo()不是YouTube iframe API错误的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Wordpress插件添加视频的时间戳链接,以便在特定时间范围内自动搜索视频。

I am using a Wordpress plugin to add timestamp links of videos that will seek the video automatically to a certain timeframe.

Javascript:

Javascript:

        function onYouTubeIframeAPIReady(){

    console.log('Confirmation of call to onYouTubeIframeAPIReady()');

    var STT = {
        settings: STTSettings,
        media: undefined,
        skipTo: undefined,
        isHTML5: false,
        isYoutube: true,

        doHTML5Skip: function() {
            STT.media.removeEventListener('canplaythrough', STT.doHTML5Skip);
            STT.media.currentTime = STT.skipTo;
            STT.media.play();
        },

        doYoutubeSkip: function() {

            STT.media.seekTo(STT.skipTo);
            STT.media.playVideo();
        }

    };




    STTSkipTo = function(time) {
        var audio       = document.getElementsByTagName('audio'),
            video       = document.getElementsByTagName('video'),
            iframe      = document.getElementsByTagName('iframe'),
            timeArray   = time.split(':').reverse(),
            seconds     = parseInt(timeArray[0]),
            minutes     = timeArray.length > 1 ? parseInt(timeArray[1]) : 0,
            hours       = timeArray.length > 2 ? parseInt(timeArray[2]) : 0;

        STT.skipTo = seconds + (minutes * 60) + (hours * 3600);

        if (STT.media) {
            console.log(STT.media.seekTo);
            STT.doSkip();

            return;
        }

        if ((parseInt(STT.settings.link_audio) && audio.length) ||
            (parseInt(STT.settings.link_video) && video.length))
        {
            STT.doSkip = STT.doHTML5Skip;

            if (parseInt(STT.settings.link_audio) && audio.length) {
                STT.media = audio[0];
            } else {
                STT.media = video[0];
            }

            STT.media.addEventListener('canplaythrough', STT.doHTML5Skip);
            STT.media.load();
            STT.media.play();
            return;
        } else if (parseInt(STT.settings.link_youtube && iframe.length)) {
            // Inspect the iframes, looking for a src with youtube in the URI
            for (var i = 0; i < iframe.length; i++) {
                if (iframe[i].src.search('youtube') !== -1) {
                    // Set up the JS interface
                    STT.doSkip = STT.doYoutubeSkip;

                    iframe[0].id = 'stt-youtube-player';
                    STT.media = new YT.Player('stt-youtube-player', {
                        events: {
                            onReady: STT.doYoutubeSkip
                        }
                    });
                    return;
                }
            }
        }

        console.log('Skip to Timestamp: No media player found!');
        return;
    }

    }

在我的本地主机上,插件工作正常无缝地,但在我的托管网站上,我得到以下错误与堆栈如下:

On my localhost, the plugin works seamlessly but on my hosted website, I get the following error with the stack as follows:


未捕获TypeError:STT.media.seekTo不是函数

Uncaught TypeError: STT.media.seekTo is not a function

我认为由于某种原因网站无法使用加载www-widgetapi.js,它是YouTube iframe API的依赖项,因此无法生成所需的函数定义。但是,我确实尝试在标题中手动包含脚本,但它仍然无法正常工作。

I think for some reason the website is unable to load the www-widgetapi.js which is a dependency for YouTube iframe API and thus is unable to generate the required function definition. However, I did try to include the script manually in the header but it still didn't work.

如果有人知道任何其他wordpress插件,请提供建议。

If anyone knows of any other wordpress plugin, please advice.

推荐答案

基于此文档,您需要设置 player.seekTo的两个参数(秒:Number,allowSeekAhead:Boolean)


寻找视频中的指定时间。如果在调用该功能时暂停播放器,它将保持暂停状态。如果从其他状态调用该函数(播放视频提示等),播放器将播放视频。

Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing, video cued, etc.), the player will play the video.




  • 参数确定玩家应该前进的时间。

    • The seconds parameter identifies the time to which the player should advance.

      玩家将在此之前前进到最近的关键帧,除非玩家已经下载了视频的一部分。用户正在寻找。

      The player will advance to the closest keyframe before that time unless the player has already downloaded the portion of the video to which the user is seeking.

      allowSeekAhead 参数确定播放器是否会向服务器发出新请求如果参数指定当前缓冲的视频数据之外的时间。

      The allowSeekAhead parameter determines whether the player will make a new request to the server if the seconds parameter specifies a time outside of the currently buffered video data.

      应该是这样的: Player.seekTo(120,true)// 120秒

      这篇关于seekTo()不是YouTube iframe API错误的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆