<template>
    <div class="app-rawitem-video">
        <video :src="playerParams.path" :autoplay="playerParams.autoplay" :controls="playerParams.showcontrols"
            :loop="playerParams.replay" :muted="playerParams.mute">
            <source :src="playerParams.path" type="video/mp4">
            <source :src="playerParams.path" type="video/ogg">
            <source :src="playerParams.path" type="video/webm">
        </video>
    </div>
</template>

<script lang="ts">
import { Util } from '@/utils';
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component({})
export default class AppVideo extends Vue {
    /**
     * 播放器唯一标识
     */
    public uuid: string = Util.createUUID();

    /**
     * 视频播放数据
     */
    @Prop() public videoParmas?: any;

    //视频播放参数
    public playerParams = {
        id: this.uuid,
        height: '100%',
        width: '100%',
        path: "",
        mute: 0.8,
        autoplay: false,
        replay: false,
        showcontrols: false
    };


    /**
     * 生命周期
     */
    public mounted() {
        this.handleStaticVideo();
    }

    /**
     * 处理静态视频播放
     *
     * @memberof AppPresetRawitem
     */
    protected handleStaticVideo() {
        if (this.videoParmas && this.videoParmas.length > 0) {
            const rawParams:any = {};
            this.videoParmas.forEach((param: any) => {
                rawParams[param.key] = param.value;
            })
            Object.assign(this.playerParams,rawParams);
        }
    }
}
</script>

<style lang='less'>
@import "./app-rawitem-video.less";
</style>
