const tasklist = require('tasklist');
const process = require('child_process');

exports.viewVideo = async (req, res, next) => {
    // const { VSPlayerPath, videoPath } = req.query;
    const { openCmd } = req.query;
    let VSPlayerList = await tasklist({
        filter:[
            `Imagename eq ${global.default_config.VSPlayer}`
        ],
        verbose: true,
    });

    // 关闭之前打开的所有视频
    let closeCmd = '';
    for(let task of VSPlayerList) {
        closeCmd += `/pid ${task.pid} `;
    }
    closeCmd = `taskkill ${closeCmd} -t -f`;
    if(VSPlayerList.length) {
        await process.execSync(closeCmd);
    }

    // 打开视频
    console.log(openCmd);
    process.exec(openCmd, function(error, stdout, stderr) {
        console.log("error:"+error);
        console.log("stdout:"+stdout);
        console.log("stderr:"+stderr);
    });
    res.json({
        code: 200,
        msg: '启动成功'
    });
    res.end();
     // res.json({})
}
