javascript - Youtube iframe api a.u() 不是函数

标签 javascript youtube youtube-iframe-api

我正在react应用程序中实现youtube iframe api,但遇到了这个错误

www-widgetapi.js:formatted:884 Uncaught TypeError: a.u is not a function
at Ya (www-widgetapi.js:formatted:884)
at Object.W (www-widgetapi.js:formatted:778)
at Object.Y [as Player] (www-widgetapi.js:formatted:973)
at e.value (Video.js:120)
at window.onYouTubeIframeAPIReady (Video.js:74)
at www-widgetapi.js:formatted:1185
at www-widgetapi.js:formatted:1189

这是函数

loadYoutube(){
 id='74YQWthFz8g'
 var data = {
        height: this.props.height,
        width: this.props.width,
        playerVars: {
            enablejsapi: 1,
            autoplay: 1, //
            controls: 0, //Turn off video controls
            modestbranding: 1, //Turn off Youtube Logo
            rel: 0, //Disable related videos at the end
            showinfo: 0, //Disable diplay of title
            disablekb: 0 //disable the keyboard
        },
        videoId: id,
        events: {
            onReady: function() {
                console.log('ready');
            },
            onStateChange: function() {
                console.log('statechange');
            }
        }
    };
    player = window.YT.Player('ytubeplayer', data);
 }
 window.onYouTubeIframeAPIReady= (e)=>{this.loadYoutube()}

最佳答案

我遇到了这个问题。对我来说,这是通过执行 player = new YT.Player('ytubeplayer', data) 解决的。

它是一个构造函数,因此需要使用new关键字。

希望这也能为您解决问题。

关于javascript - Youtube iframe api a.u() 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50967828/

相关文章:

javascript - 声明 JavaScript 成员函数的最佳实践

javascript - 在莲花脚本中执行 22 位数字的除法

javascript - jQuery 关闭 Div 窗口 + cookie

YouTube JS API : Detect "embedding has been disabled"

javascript - 在播放另一个 YouTube iframe 时停止任何嵌入式 YouTube iframe

javascript - CakePHP:在 View 的标题中包含js文件

android - Activity 泄露了原本绑定(bind)的 ServiceConnection com.google.android.youtube.player.internal.r$e@43cb2348

javascript - Youtube Iframe API事件在IOS设备上不起作用

android - 将 iframe 添加到 Appcelerator 应用程序

javascript - Youtube Iframe API - 检测播放列表的结尾