zoukankan      html  css  js  c++  java
  • vue组件-视频播放之video.js

        最近在练手一个小项目,想给首页增加一个视频介绍(如下图)。涉及到了vue视频播放的功能,所以在网上了解了一下。

        相关的插件是Video.js,官网讲解比较详细,我罗列出来,可以根据自己需要去查看。

    官网地址:

        1.video.js整合vue的地址:https://docs.videojs.com/tutorial-vue.html

        2.video.js框架API的地址:https://docs.videojs.com/tutorial-options.html

    简单使用

    第一步,添加依赖

    npm install --save-dev video.js
    

    第二步,在main.js中引入Video.js及样式

    import Video from 'video.js'
    import 'video.js/dist/video-js.css'
    
    Vue.prototype.$video = Video //引入Video播放器
    

    创建通用播放器(官网vue整合代码)

    <template>
        <div>
            <video ref="videoPlayer" class="video-js"></video>
        </div>
    </template>
    
    <script>
    import videojs from 'video.js';
    
    export default {
        props: {
            options: {
                type: Object,
                default() {
                    return {};
                }
            }
        },
        data() {
            return {
                player: null
            }
        },
        mounted() {
            this.player = this.$video(this.$refs.videoPlayer, this.options, function onPlayerReady() {
                console.log('onPlayerReady', this);
            })
        },
        beforeDestroy() {
            if (this.player) {
                this.player.dispose()
            }
        }
    }
    </script>
    

    根据需要创建具体播放器(具体参数可以查看官网API)

    <template>
        <div>
            <video-player :options="videoOptions"/>
        </div>
    </template>
    <script>
    import VideoPlayer from "./VideoPlayer";
    
    export default {
        components: {
            VideoPlayer
        },
        data() {
            return {
                videoOptions: {
                    autoplay: 'muted',//自动播放
                    controls: true,//用户可以与之交互的控件
                    loop:true,//视频一结束就重新开始
                    muted:false,//默认情况下将使所有音频静音
                    aspectRatio:"16:9",//显示比率
                    fullscreen:{
                        options: {navigationUI: 'hide'}
                    },
                    sources: [
                        {
                            src: require("@/assets/video/index/oceans.mp4"),
                            type: "video/mp4"
                        }
                    ]
                }
            };
        }
    }
    
    </script>
    <style scoped>
    </style>
    
    

        以上就是,Video.js的简单使用,是不是很简单。

    最后:

  • 相关阅读:
    7.12Java+TestNG环境搭建
    7.15Java之调用API接口传表单获取返回信息
    7.12理解Cookie与token
    7.13一次完整的Http请求过程(3)
    7.13一次完整的Http请求过程(2)
    7.13一次完整的Http请求过程
    PostgreSql安装(win 2003 下)
    实用工具(渐变更新中)
    .net Ajax系列(2)调用多Web Service
    .net Ajax系列(1)调用Web Service
  • 原文地址:https://www.cnblogs.com/perferect/p/13300791.html
Copyright © 2011-2022 走看看