Fetch the repository succeeded.
#include "mainadapte.h"
#include <QtWidgets>
#include <QPaintEvent>
#include <QPainter>
#include<qtlog.h>
#include"videoitem.h"
MainAdapte::MainAdapte(QObject *parent) : QObject(parent)
{
// qRegisterMetaType<QVariantMap>("QVariantMap");
// qRegisterMetaType<QVariantMap>("QVariantMap&");
// avformat_network_init();
// av_register_all();
qRegisterMetaType<QImage>("QImage");
qRegisterMetaType<QTextCursor>("QTextCursor");
if(!m_ffmpeg){
m_ffmpeg = new FFmpegOpt(this);
connect(m_ffmpeg,&FFmpegOpt::sig_play,this,&MainAdapte::s_play);
}
m_widget = new QWidget(nullptr);
m_widget->installEventFilter(this);
m_widget->resize(600,400);
m_widget->show();
}
void MainAdapte::startExe()
{
if(!m_engine)
m_engine = new QQmlApplicationEngine(this);
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
qmlRegisterType<VideoItem>("VideoItem", 1, 0, "VideoItem");
m_engine->rootContext()->setContextProperty("CPPObJ",this);
m_engine->load(url);
QTimer::singleShot(500,this,[=]{
QVariantMap a;
a["tst"] = 2222222;
emit sig_callQmlFunc("1111111",a);});
}
QVariantMap MainAdapte::callCppFunc(QString funcStr, QVariantMap pData)
{
if(funcStr == "stop"){
m_ffmpeg->stopPlay();
}else if(funcStr == "playVideo"){
pData = m_ffmpeg->openVideo("./tst.mp4");
pData["total"] = m_ffmpeg->getTotal();
}else if(funcStr == "pauseVideo"){
m_ffmpeg->pausePlay(!m_ffmpeg->isPlay());
}else if(funcStr == "getTime"){
pData["pos"] = m_ffmpeg->getPos();
pData["total"] = m_ffmpeg->getTotal();
}else if(funcStr == "seekToPos"){
m_ffmpeg->seekPos( pData["pos"].toDouble() );
}else if(funcStr == "openUrlVideo"){
pData = m_ffmpeg->openVideo(pData["url"].toString());
// m_ffmpeg->openUrlVideo(pData["url"].toString());
}
return pData;
}
bool MainAdapte::eventFilter(QObject *watched, QEvent *event)
{
if(watched == m_widget){
QEvent::Type _type = event->type();
if(_type == QEvent::Paint){
QPaintEvent *paintE = static_cast<QPaintEvent*>(event);
QPainter p(m_widget);
p.drawImage(paintE->rect(),m_img);
}
}
return QObject::eventFilter(watched,event);
}
void MainAdapte::s_play( QImage img)
{
m_img = img;
m_widget->update();
static VideoItem *videoItem = nullptr;
if(!videoItem){
QObject *pRoot = m_engine->rootObjects().first();
videoItem = pRoot->findChild<VideoItem *>("videoItem");
}
videoItem->setImg(img);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。