#ifndef EMOVIE_H
#define EMOVIE_H

#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QGraphicsVideoItem>
#include <QGraphicsProxyWidget>
#include "eobject.h"
#include "QProcess"
#include "LoUIClass/loemptydialog.h"
#include <QVideoWidget>
//#include "videoplayer.h"
//#include "glyuvwidget.h"
class eMovie : public eObject
{
    Q_OBJECT
public:
    struct Data {
        QString name;
        QString path;
        QString strRawName;
        QString strRawPath;
        int     aspectRatioMode;
        int     playDuration=10;
        int     playTimes;
    };

public:
    explicit eMovie(QRectF rectInit,const QString &file,QWidget *pp, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
    explicit eMovie(const QJsonObject &json, const QString &pRoot, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
    ~eMovie() override;
//    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
    Data getData(){return m_attr;}
    double GetVideoTimeRawSpan(QString strFilePathName);

private:
    void init(bool bPlay);
    void InitFfmpegSdl();
    void Delay(int msec);
public:
    static void setElement(const QJsonObject &json, Data &attr);

public:
    static QString filters() { return tr("Movie(*.mp4 *.mkv *.rm *.rmvb *.avi *.wmv *.mov);;"
                                         "Flash(*.flv *.swf)"); }
    void deleteContent();
public:
    virtual int type() const override { return eObject::Movie; }
    virtual QWidget* wAttr() override;
    virtual QWidget* wAttrElement() override;
    virtual QJsonObject save(const QString &pRoot) override;
    virtual QStringList filesList() const override;
    virtual QJsonObject elementJson() const override;

signals:
    void sigSetTipTextContent(QString);
public slots:
    virtual void playElectment() override;
    virtual void stopElectment() override;
    void onResChanged(const QString &file,const QString &RawFile);
    void onAttrChanged(const eMovie::Data &data);
    void onAdjustMovieRect();
    void continueConvert(int,QProcess::ExitStatus);
    void outputCommand();
    void outputError();
    void onConverProgress();
//    void slotShowYuv_liuyi(uchar *ptr,uint width,uint height); //显示一帧Yuv图像

protected:
    void setPlayArg(int armode, int pd, int pt);

private:
    QMediaPlayer       *m_vPlayer=nullptr;
    QMediaPlaylist     *m_vPlayList=nullptr;
    QGraphicsVideoItem *m_vWidget=nullptr;
 //   QVideoWidget *m_vWidget=nullptr;
//    QGraphicsProxyWidget *m_vffmpegWidget=nullptr;
    //VideoPlayer *mPlayer=nullptr; /**播放线程**/
    //glyuvwidget *openGLWidget=nullptr;
    QImage *m_Image;
    Data               m_attr;
    QProcess *process=nullptr;
    LoEmptyDialog *m_pProgressConvertVideo;
    QString ConvertVideoFormat(QString strFile);
    QString ConvertVideoFormatByFFmpeg(QString strFile);
    QTimer *m_pConverProgressTimer=nullptr;
    QString m_strOutFilePathName="";
    qreal m_display_aspect_ratio=1;
    int m_videoTimeLong=15;
    QWidget *m_parentWidget=nullptr;

};

#endif // EMOVIE_H
