【问题标题】:How to use YouTube API with Gulp (minified file doesn't contain YouTube callback methods)如何在 Gulp 中使用 YouTube API(缩小文件不包含 YouTube 回调方法)
【发布时间】:2015-09-20 09:37:18
【问题描述】:

我不能使用 YouTube Player API 方法,因为它们已被 Laravel Elixir (Gulp) 在我缩小的 .js 文件中删除。

下面的方法不包含在我的缩小的.js 文件中,因为它们没有在我创建的.js 文件中调用(实际上,它们在YouTube iFrame API 中调用)。

onYouTubeIframeAPIReady
onPlayerReady
onPlayerStateChange

这个问题有什么解决办法吗?

【问题讨论】:

    标签: javascript gulp youtube-javascript-api laravel-elixir


    【解决方案1】:

    解决此问题的唯一方法是致电onYouTubeIframeAPIReady()

    为此,我添加了一个条件:

    function onYouTubeIframeAPIReady(init) {
       if (init === "init") {
           return;
       }
       // Init your YouTube Player here, after the condition.
    }
    
    // First call here : The minifier notices the method is used, so it won't delete it
    onYouTubeIframeAPIReady("init");
    
    // Later, YouTube API will call this method
    // (YouTube doesn't pass any parameters, so the player will be initialized in this case)
    // YouTube API : onYouTubeIframeAPIReady();
    

    【讨论】:

      猜你喜欢
      • 2017-11-01
      • 2016-03-26
      • 1970-01-01
      • 2016-12-05
      • 2015-11-30
      • 2015-12-19
      • 2014-02-23
      • 2018-05-02
      • 1970-01-01
      相关资源
      最近更新 更多