83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include "MediaPlayer.h"
|
|
|
|
#include <QVideoWidget>
|
|
#include <QGridLayout>
|
|
#include <QUrl>
|
|
#include <QDebug>
|
|
|
|
MediaPlayer::MediaPlayer(QWidget* parent)
|
|
: QObject(parent) {
|
|
//, m_meidaPlayer(new QMediaPlayer) {
|
|
|
|
|
|
//QGridLayout* layout = new QGridLayout(this);
|
|
// QVideoWidget* widget = new QVideoWidget;
|
|
// m_meidaPlayer->setVideoOutput(widget);
|
|
// layout->addWidget(widget);
|
|
// layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
// auto audioOutput = new QAudioOutput(this);
|
|
// m_meidaPlayer->setAudioOutput(audioOutput);
|
|
// connect(m_meidaPlayer, &QMediaPlayer::mediaStatusChanged, this, &MediaPlayer::mediaStatusChanged);
|
|
|
|
connect(&vlcPlayer_, &VlcMediaPlayer::VideoDataOutput, this, &MediaPlayer::SignalFrame, Qt::QueuedConnection);
|
|
connect(&vlcPlayer_, &VlcMediaPlayer::Stopped, this, &MediaPlayer::Stopped, Qt::QueuedConnection);
|
|
}
|
|
|
|
MediaPlayer::~MediaPlayer() {
|
|
//delete m_meidaPlayer;
|
|
}
|
|
|
|
bool MediaPlayer::Play(const QString& path) {
|
|
if (vlcPlayer_.IsPlaying()) {
|
|
vlcPlayer_.Stop();
|
|
}
|
|
|
|
/*qDebug() << __FUNCTION__ << "play path:" << path;
|
|
m_meidaPlayer->setSource(QUrl::fromLocalFile(path));
|
|
m_meidaPlayer->play();
|
|
m_meidaPlayer->setPosition(0);*/
|
|
const QString moviePath = path;
|
|
vlcPlayer_.Play(moviePath);
|
|
//show();
|
|
return true;
|
|
}
|
|
|
|
void MediaPlayer::Stop() {
|
|
/*if (!m_playing) {
|
|
return;
|
|
}
|
|
|
|
m_playing = false;
|
|
m_meidaPlayer->stop();*/
|
|
|
|
if (!vlcPlayer_.IsPlaying()) {
|
|
vlcPlayer_.Stop();
|
|
}
|
|
}
|
|
|
|
void MediaPlayer::slotSetOneFrame(QImage image) {
|
|
src_mImage = mImage = image;
|
|
//mImage.save("d:/1.png");
|
|
// update();
|
|
}
|
|
//
|
|
//void MediaPlayer::paintEvent(QPaintEvent* e) {
|
|
// QPainter painter(this);
|
|
//
|
|
// painter.setRenderHint(QPainter::Antialiasing);
|
|
// painter.setRenderHint(QPainter::TextAntialiasing);
|
|
// painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
// //painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
|
//
|
|
// //painter.setBrush(Qt::black);
|
|
// //painter.drawRect(0,0,this->width(),this->height());
|
|
//
|
|
// if (mImage.size().width() <= 0) return;
|
|
//
|
|
//// QImage img = mImage.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
//
|
|
//
|
|
// painter.drawImage(rect(), mImage);
|
|
//}
|