import {getImages} from '@/plugins/images.js'
let multipleDecoderJs = getImages('/assetsMobile/script/flvPlayer/flvplayer-decoder-multiple.js')
let baselineDecoderJs = getImages('/assetsMobile/script/flvPlayer/flvplayer-decoder-baseline.js')
export default function createFlvPlayer(elementId,url, isplay = true) {
    let flv = null;
   
    const play = ()=>{
        if(flv) flv.play()
    }
    const pause = ()=>{
        if(flv) flv.pause()
    }
    const destroyVideo = ()=>{
        if (flv) {
            flv.pause && flv.pause();
            flv.destroy && flv.destroy();
            flv = null;
        }
    }
    const createPlayer = (el, url) => {
        if (!flv) {
            flv = new window.FlvPlayer({
                container: el,
                url,
                decoder: multipleDecoderJs,
                cache: false,
                muted: true,
                videoChunk: 128 * 128,
                live: true,
                autoPlay: true,
                hasAudio: false,
                debug: true,
                control: true
            })
        }
    }
    createPlayer(elementId,url);

    return {
        createPlayer,
        play,
        pause,
        destroyVideo
    }
}