Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js video.js youtube延迟加载_Vue.js_Lazy Loading_Video.js - Fatal编程技术网

Vue.js video.js youtube延迟加载

Vue.js video.js youtube延迟加载,vue.js,lazy-loading,video.js,Vue.js,Lazy Loading,Video.js,我的主页上有大约100个电影缩略图,每个缩略图上都有一个播放图标,可以通过video.js播放器启动youtube视频。 问题是video.js预加载了所有youtube资源,我的主页有50mb。 是否有一种方法仅在用户播放视频或其他解决方案时加载资源? 该网站是用VUE制作的 这里是播放器组件的代码: <template> <div> <video ref="player" class="video-js&qu

我的主页上有大约100个电影缩略图,每个缩略图上都有一个播放图标,可以通过video.js播放器启动youtube视频。 问题是video.js预加载了所有youtube资源,我的主页有50mb。 是否有一种方法仅在用户播放视频或其他解决方案时加载资源? 该网站是用VUE制作的

这里是播放器组件的代码:

<template>
    <div>
        <video ref="player" class="video-js"></video>
    </div>
</template>
<script>
import "video.js/dist/video-js.min.css";
import videojs from "video.js";
import "videojs-youtube";
import "@devmobiliza/videojs-vimeo";

export default {
    name: "UtTrailerPlayer",
    props: {
        src: {
            type: String,
            default: null,
        },
        type: {
            type: String,
            default: null,
        },
    },
    data: () => {
        return {
            player: null,
            playerOpts: {
                controls: false,
                width: 320,
                height: 240,
                debug: true,
                fluid: true,
                liveui: false,
        preload: "none",
                techOrder: ["youtube"],
                languages: ["it"],
            },
        };
    },
    methods: {
        init: function() {
            if (this.src) {
                let opts = {
                    controls: false,
                    width: 320,
                    height: 240,
                    debug: true,
                    fluid: true,
                    liveui: false,
          preload: "none",
                    techOrder: ["youtube"],
                    languages: ["it"],
                    sources: [],
                };

                if (this.type == "youtube") {
                    opts["sources"] = [
                        {
                            type: "video/youtube",
                            src: this.src,
                        },
                    ];
                } else if (this.type == "vimeo") {
                    opts["sources"] = [
                        {
                            type: "video/vimeo",
                            src: this.src,
                            vimeo: {
                                color: "#F2B544",
                            },
                        },
                    ];
                }

                const player = this.$refs.player;
                this.$nextTick(() => {
                    if (opts.sources.length > 0 && player) {
                        // console.log(opts.sources[0]);
                        // this.player = videojs(player, opts, this.onPlayerReady());
                        this.player = videojs(player, opts);
                    } else {
                        // this.$emit("error");
                    }
                });
            } else {
                console.log("no src");
            }
        },
        onPlayerReady: function() {
            console.log("player ready");
        },
        play: function() {
            if (this.player) {
                this.player.play();
            }
        },
        pause: function() {
            if (this.player) {
                this.player.pause();
            }
        },
    },
    mounted: function() {
        this.init();
    },
    beforeDestroy() {
        if (this.player) {
            this.player.dispose();
        }
    },
};
</script>
<style lang="scss"></style>

导入“video.js/dist/video js.min.css”;
从“video.js”导入videojs;
导入“videojs youtube”;
导入“@devmobiliza/videojs vimeo”;
导出默认值{
名称:“UtTrailerPlayer”,
道具:{
src:{
类型:字符串,
默认值:null,
},
类型:{
类型:字符串,
默认值:null,
},
},
数据:()=>{
返回{
玩家:空,
玩家提示:{
控件:false,
宽度:320,
身高:240,
是的,
流体:是的,
李维:错,
预加载:“无”,
techOrder:[“youtube”],
语言:[“it”],
},
};
},
方法:{
init:function(){
if(this.src){
让选项={
控件:false,
宽度:320,
身高:240,
是的,
流体:是的,
李维:错,
预加载:“无”,
techOrder:[“youtube”],
语言:[“it”],
资料来源:[],
};
如果(this.type==“youtube”){
选项[“源”]=[
{
键入:“视频/youtube”,
src:this.src,
},
];
}else if(this.type==“vimeo”){
选项[“源”]=[
{
类型:“视频/vimeo”,
src:this.src,
维梅奥:{
颜色:#F2B544“,
},
},
];
}
常量玩家=此。$refs.player;
这个.$nextTick(()=>{
if(opts.sources.length>0&&player){
//console.log(opts.sources[0]);
//this.player=videojs(player,opts,this.onPlayerReady());
this.player=videojs(播放器,选项);
}否则{
//此。$emit(“错误”);
}
});
}否则{
控制台日志(“无src”);
}
},
onPlayerReady:函数(){
控制台日志(“播放器就绪”);
},
播放:函数(){
if(this.player){
这个.player.play();
}
},
暂停:函数(){
if(this.player){
this.player.pause();
}
},
},
挂载:函数(){
this.init();
},
在…之前{
if(this.player){
this.player.dispose();
}
},
};