qt/LedOK/player/elevideo.cpp
2022-01-20 10:08:17 +08:00

18 lines
516 B
C++

#include "elevideo.h"
#include <QMediaPlayer>
EleVideo::EleVideo(QString path, QWidget *parent) : QVideoWidget{parent} {
setAspectRatioMode(Qt::IgnoreAspectRatio);
QMediaPlayer* player = new QMediaPlayer(this);
player->setMedia(QUrl::fromLocalFile(path));
player->setVideoOutput(this);
if(isVisible()) player->play();
}
void EleVideo::showEvent(QShowEvent *) {
((QMediaPlayer*)mediaObject())->play();
}
void EleVideo::hideEvent(QHideEvent *) {
((QMediaPlayer*)mediaObject())->stop();
}