首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从YTConfig Iframe流星包导入YT和YouTube

从YTConfig Iframe流星包导入YT和YouTube
EN

Stack Overflow用户
提问于 2016-08-15 18:25:33
回答 1查看 1.1K关注 0票数 0

我们正在使用adrianliaw:youtube-iframe-api包来显示项目中的youtube iframes。

这之前很好,但我们决定将项目的某些部分转移到他们自己的包中。这样做之后,我似乎无法将YTYTConfig对象导入到我们的包中。

这就是我所拥有的:

package.js

代码语言:javascript
复制
Package.onUse(function(api) {
    api.versionsFrom('METEOR@0.9.1.1');

  // API Use - Both client and server
  api.use([
    'ecmascript',
    'templating',
    'fourseven:scss'
  ], ['client', 'server']);

  // API Use - Client only
  api.use([
    'adrianliaw:youtube-iframe-api'
  ], ['client']);
});

youtube-display.js

代码语言:javascript
复制
import { YT, YTConfig } from 'meteor/adrianliaw:youtube-iframe-api';

/**
 * Video display controller
 * Assuming youtube-only for now
 */

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player,
    videoId,
    videoElement,
    isPreview = false,
    isMuted = false;

onYouTubeIframeAPIReady = function() {
    player = new YT.Player(videoElement, {
        height: window.innerHeight,
        width: window.innerWidth,
        videoId: videoId,
        playerVars: {
            controls: 0,
            showinfo: 0,
            modestbranding: 1,
            iv_load_policy: 3,
            rel: 0
        },
        events: {
            onReady: function (event) {
                if ( ! isPreview ) {
                    // Play video when player ready.
                    event.target.playVideo();

                    if ( isMuted ) {
                        event.target.mute();
                    }
                }
            }
        }
    });
}

Template.HBModule_youtube_Display.onCreated(function() {
    videoId = Template.instance().data.media.youtubeId;

    if ( Template.instance().data.preview ) {
        isPreview = true;
    }

    if ( Template.instance().data.muted ) {
        isMuted = true;
    }
});

Template.HBModule_youtube_Display.onRendered(function() {
    videoElement = Template.instance().$('.module__video')[0];

    // Start
    YT.load();
});

Template.HBModule_youtube_Display.onDestroyed(function() {
    player.destroy()
});

我得到了一个错误:_adrianliawYoutubeIframeApi.YT.load is not a function

就像我说的,减去显示文件顶部的导入,这一切都是完美的。

任何帮助都将不胜感激。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-19 15:20:20

诀窍是去掉youtube-display.js顶部的导入,并按照下面的答案将onYouTubeIframeAPIReady函数更改为window.onYouTubeIframeAPIReadyhttps://stackoverflow.com/a/16701359/5463842

编辑:哦!而且,将@1.3.122添加到包中,就像我使用的是一个旧版本一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38960760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档