#include <QFileDialog>
#include <QStandardPaths>
#include <QPainter>
#include <QCloseEvent>
#include <QEvent>
#include <QFileInfoList>
#include <QMenu>
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
extern "C"
{
#include "libavformat/avformat.h"
}
#define VOLUME_INT (13)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
decoder(new Decoder),
menuTimer(new QTimer),
progressTimer(new QTimer),
menuIsVisible(true),
isKeepAspectRatio(false),
autoPlay(false),
loopPlay(false),
closeNotExit(false),
playState(Decoder::STOP),
seekInterval(15)
{
ui->setupUi(this);
qRegisterMetaType<Decoder::PlayState>("Decoder::PlayState");
menuTimer->setInterval(8000);
menuTimer->start(5000);
progressTimer->setInterval(500);
initUI();
initTray();
initSlot();
initFFmpeg();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initUI()
{
this->setWindowTitle("QtPlayer");
this->setWindowIcon(QIcon(":/image/player.ico"));
this->centralWidget()->setMouseTracking(true);
this->setMouseTracking(true);
image = QImage(":/image/MUSIC.jpg");
ui->labelTime->setStyleSheet("background: #5FFFFFFF;");
ui->labelTime->setText(QString("00.00.00 / 00:00:00"));
ui->btnNext->setIcon(QIcon(":/image/next.ico"));
ui->btnNext->setIconSize(QSize(48, 48));
ui->btnNext->setStyleSheet("background: transparent;");
ui->btnPreview->setIcon(QIcon(":/image/forward.ico"));
ui->btnPreview->setIconSize(QSize(48, 48));
ui->btnPreview->setStyleSheet("background: transparent;");
ui->btnStop->setIcon(QIcon(":/image/stop.ico"));
ui->btnStop->setIconSize(QSize(48, 48));
ui->btnStop->setStyleSheet("background: transparent;");
ui->btnPause->setIcon(QIcon(":/image/play.ico"));
ui->btnPause->setIconSize(QSize(48, 48));
ui->btnPause->setStyleSheet("background: transparent;");
setHide(ui->btnOpenLocal);
setHide(ui->btnOpenUrl);
setHide(ui->btnStop);
setHide(ui->btnPause);
setHide(ui->btnNext);
setHide(ui->btnPreview);
setHide(ui->lineEdit);
setHide(ui->videoProgressSlider);
setHide(ui->labelTime);
ui->videoProgressSlider->installEventFilter(this);
}
void MainWindow::initFFmpeg()
{
// av_log_set_level(AV_LOG_INFO);
avfilter_register_all();
/* ffmpeg init */
av_register_all();
/* ffmpeg network init for rtsp */
if (avformat_network_init()) {
qDebug() << "avformat network init failed";
}
/* init sdl audio */
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
qDebug() << "SDL init failed";
}
}
void MainWindow::initSlot()
{
connect(ui->btnOpenLocal, SIGNAL(clicked(bool)), this, SLOT(buttonClickSlot()));
connect(ui->btnOpenUrl, SIGNAL(clicked(bool)), this, SLOT(buttonClickSlot()));
connect(ui->btnStop, SIGNAL(clicked(bool)), this, SLOT(buttonClickSlot()));
connect(ui->btnPause, SIGNAL(clicked(bool)), this, SLOT(buttonClickSlot()));
connect(ui->btnNext, SIGNAL(clicked(bool)), this, SLOT(buttonClickSlot()));
connect(ui->btnPreview, SIGNAL(clicked(bool)), this, SLOT(buttonClickSlot()));
connect(ui->lineEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(editText()));
connect(menuTimer, SIGNAL(timeout()), this, SLOT(timerSlot()));
connect(progressTimer, SIGNAL(timeout()), this, SLOT(timerSlot()));
connect(ui->videoProgressSlider, SIGNAL(sliderMoved(int)), this, SLOT(seekProgress(int)));
connect(this, SIGNAL(selectedVideoFile(QString,QString)), decoder, SLOT(decoderFile(QString,QString)));
connect(this, SIGNAL(stopVideo()), decoder, SLOT(stopVideo()));
connect(this, SIGNAL(pauseVideo()), decoder, SLOT(pauseVideo()));
connect(decoder, SIGNAL(playStateChanged(Decoder::PlayState)), this, SLOT(playStateChanged(Decoder::PlayState)));
connect(decoder, SIGNAL(gotVideo(QImage)), this, SLOT(showVideo(QImage)));
connect(decoder, SIGNAL(gotVideoTime(qint64)), this, SLOT(videoTime(qint64)));
}
void MainWindow::initTray()
{
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
trayIcon->setToolTip(tr("QtPlayer"));
trayIcon->setIcon(QIcon(":/image/player.ico"));
trayIcon->show();
QAction *minimizeAction = new QAction(tr("最小化 (&I)"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
QAction *restoreAction = new QAction(tr("还原 (&R)"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
QAction *quitAction = new QAction(tr("退出 (&Q)"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
/* tray right click menu */
QMenu *trayIconMenu = new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
}
void MainWindow::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
int width = this->width();
int height = this->height();
painter.setBrush(Qt::black);
painter.drawRect(0, 0, width, height);
if (isKeepAspectRatio) {
QImage img = image.scaled(QSize(width, height), Qt::KeepAspectRatio);
/* calculate display position */
int x = (this->width() - img.width()) / 2;
int y = (this->height() - img.height()) / 2;
painter.drawImage(QPoint(x, y), img);
} else {
QImage img = image.scaled(QSize(width, height));
painter.drawImage(QPoint(0, 0), img);
}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (closeNotExit) {
/* ignore original close event */
event->ignore();
/* hide window & not show in task bar */
this->hide();
}
}
void MainWindow::changeEvent(QEvent *event)
{
/* judge whether is window change event */
if (event->type() == QEvent::WindowStateChange) {
if (this->windowState() == Qt::WindowMinimized) {
/* hide window & not show in task bar */
event->ignore();
this->hide();
} else if (this->windowState() == Qt::WindowMaximized) {
}
}
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->videoProgressSlider) {
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::LeftButton) {
int dur = ui->videoProgressSlider->maximum() - ui->videoProgressSlider->minimum();
int pos = ui->videoProgressSlider->minimum() + dur * ((double)mouseEvent->x() / ui->videoProgressSlider->width());
if(pos != ui->videoProgressSlider->sliderPosition()) {
ui->videoProgressSlider->setValue(pos);
decoder->seekProgress(static_cast<qint64>(pos) * 1000000);
}
}
}
}
return QObject::eventFilter(obj, event);
}
void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
int progressVal;
int volumnVal = decoder->getVolume();
switch (event->key()) {
case Qt::Key_Up:
if (volumnVal + VOLUME_INT > SDL_MIX_MAXVOLUME) {
decoder->setVolume(SDL_MIX_MAXVOLUME);
} else {
decoder->setVolume(volumnVal + VOLUME_INT);
}
break;
c
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
QtPlayer base on FFmpeg (239个子文件)
libSDL2.a 7.6MB
libSDL2_test.a 469KB
libavdevice.dll.a 392KB
libSDL2.dll.a 375KB
libavutil.dll.a 327KB
libavcodec.dll.a 162KB
libavformat.dll.a 144KB
libavfilter.dll.a 49KB
libswscale.dll.a 22KB
libswresample.dll.a 15KB
libSDL2main.a 12KB
libpostproc.dll.a 7KB
sdl2-config.cmake 483B
mainwindow.cpp 21KB
decoder.cpp 15KB
audiodecoder.cpp 12KB
avpacketqueue.cpp 1016B
main.cpp 359B
videodecoder.cpp 100B
avdevice-57.def 14KB
avutil-55.def 12KB
avcodec-57.def 6KB
avformat-57.def 6KB
avfilter-6.def 2KB
swscale-4.def 756B
swresample-2.def 478B
postproc-54.def 233B
SDL_opengl_glext.h 714KB
avcodec.h 213KB
avformat.h 113KB
SDL_opengles2_gl2ext.h 96KB
SDL_opengl.h 81KB
SDL_egl.h 72KB
SDL_video.h 44KB
avfilter.h 42KB
SDL_hints.h 39KB
SDL_haptic.h 38KB
opt.h 35KB
SDL_render.h 34KB
pixfmt.h 33KB
SDL_audio.h 33KB
SDL_opengles2_gl2.h 31KB
avio.h 31KB
SDL_events.h 29KB
frame.h 26KB
mem.h 23KB
hwcontext.h 22KB
swresample.h 21KB
SDL_stdinc.h 21KB
SDL_surface.h 19KB
intreadwrite.h 18KB
avdevice.h 17KB
SDL_pixels.h 17KB
common.h 15KB
pixdesc.h 15KB
SDL_keycode.h 15KB
SDL_scancode.h 15KB
avstring.h 14KB
SDL_test_fuzzer.h 13KB
SDL_joystick.h 12KB
SDL_gamecontroller.h 12KB
swscale.h 12KB
log.h 11KB
imgutils.h 11KB
SDL_assert.h 11KB
SDL_mouse.h 11KB
SDL_thread.h 11KB
buffer.h 10KB
samplefmt.h 10KB
SDL_opengles2_khrplatform.h 10KB
SDL_atomic.h 10KB
SDL_vulkan.h 10KB
channel_layout.h 9KB
avutil.h 9KB
SDL_syswm.h 9KB
hash.h 8KB
dict.h 8KB
version.h 8KB
spherical.h 8KB
SDL_rwops.h 8KB
mathematics.h 8KB
vdpau.h 8KB
bprint.h 8KB
SDL_system.h 7KB
parseutils.h 7KB
SDL_mutex.h 7KB
buffersrc.h 6KB
SDL_log.h 6KB
SDL_endian.h 6KB
SDL_keyboard.h 6KB
buffersink.h 6KB
hwcontext_d3d11va.h 6KB
SDL_config.h 6KB
xvmc.h 6KB
vda.h 6KB
audio_fifo.h 6KB
fifo.h 6KB
rational.h 6KB
SDL_shape.h 6KB
cpu.h 5KB
共 239 条
- 1
- 2
- 3
资源评论
- zhuozhuoge2018-11-19编译不了,不过牛逼吹的挺好,值得借鉴
- 阿里尼2022-04-27编译一推错误
胧霖
- 粉丝: 83
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 自学文档,用于自己学习
- asp代码ASP考试成绩分析系统的设计与实现(源代码+论文)
- openssh-9.7p1-1.ky10.aarch64-no-ssh-copy-id.tgz
- asp代码ASP具有动态口令认证机制的网上投票系统的设计(源代码+论文)
- asp代码ASP局域网文件共享及检索系统的设计与开发(源代码+论文)
- asp代码ASP酒店预定管理系统设计(论文+源代码+开题报告)
- javaweb毕业设计-学生住宿管理系统JAVA(可做课程设计).rar
- asp代码ASP教师信息管理系统设计(源代码+论文)
- c语言链表的基本操作实现
- python冒泡排序(Bubble Sort).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功